lib/WWW/Hetzner/Robot/CLI/Cmd/Key.pm untested

filter: Statementstmt 0.0% 0 / 27 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 8 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 43 CC 2 SCAR 12.0
CC
2
Cov
0%
execute
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 3.3
1 package WWW::Hetzner::Robot::CLI::Cmd::Key;
2 # ABSTRACT: Robot SSH key commands
3  
4 our $VERSION = '0.100';
5  
6 use Moo;
7 use MooX::Cmd;
8 use MooX::Options usage_string => 'USAGE: hrobot.pl key [options]';
9  
10  
11 sub execute {
12 my ($self, $args, $chain) = @_;
13 my $root = $chain->[0];
14 my $robot = $root->robot;
15  
16 # Default: list keys
17 my $keys = $robot->keys->list;
18  
19 if ($root->output eq 'json') {
20 require JSON::MaybeXS;
21 print JSON::MaybeXS::encode_json([map { +{
22 name => $_->name,
23 fingerprint => $_->fingerprint,
24 type => $_->type,
25 size => $_->size,
26 } } @$keys]);
27 print "\n";
28 } else {
29 printf "%-20s %-50s %-10s %s\n", 'NAME', 'FINGERPRINT', 'TYPE', 'SIZE';
30 for my $k (@$keys) {
31 printf "%-20s %-50s %-10s %s\n",
32 $k->name // '',
33 $k->fingerprint // '',
34 $k->type // '',
35 $k->size // '';
36 }
37 }
38 }
39  
40 1;
41  
42 __END__