lib/WWW/Hetzner/CLI/Cmd/Image.pm untested

filter: Statementstmt 0.0% 0 / 28 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 6 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 44 CC 3 SCAR 18.4
CC
3
Cov
0%
execute
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 6.3
1 package WWW::Hetzner::CLI::Cmd::Image;
2 # ABSTRACT: Image commands
3  
4 our $VERSION = '0.100';
5  
6 use Moo;
7 use MooX::Cmd;
8 use MooX::Options usage_string => 'USAGE: hcloud.pl image [--type system|snapshot|backup] [options]';
9 use JSON::MaybeXS qw(encode_json);
10  
11 option type => (
12 is => 'ro',
13 format => 's',
14 doc => 'Filter by type (system, snapshot, backup)',
15 );
16  
17 sub execute {
18 my ($self, $args, $chain) = @_;
19  
20 my $main = $chain->[0];
21 my $cloud = $main->cloud;
22  
23 my %params;
24 $params{type} = $self->type if $self->type;
25  
26 my $images = $cloud->images->list(%params);
27  
28 if ($main->output eq 'json') {
29 print encode_json($images), "\n";
30 return;
31 }
32  
33 printf "%-10s %-20s %-10s %-15s %s\n",
34 'ID', 'NAME', 'TYPE', 'OS', 'STATUS';
35 print "-" x 70, "\n";
36  
37 for my $i (@$images) {
38 printf "%-10s %-20s %-10s %-15s %s\n",
39 $i->{id},
40 $i->{name} // '-',
41 $i->{type},
42 ($i->{os_flavor} // '') . ' ' . ($i->{os_version} // ''),
43 $i->{status};
44 }
45 }
46  
47 1;
48  
49 __END__