lib/WWW/Hetzner/CLI/Cmd/PrimaryIp/Cmd/List.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 10 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 51 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::PrimaryIp::Cmd::List;
2 # ABSTRACT: List primary IPs
3  
4 our $VERSION = '0.100';
5  
6 use Moo;
7 use MooX::Cmd;
8 use MooX::Options protect_argv => 0, usage_string => 'USAGE: hcloud.pl primary-ip list';
9 use JSON::MaybeXS qw(encode_json);
10  
11 sub execute {
12 my ($self, $args, $chain) = @_;
13  
14 my $main = $chain->[0];
15 my $cloud = $main->cloud;
16  
17 my $pips = $cloud->primary_ips->list;
18  
19 if ($main->output eq 'json') {
20 print encode_json([ map { $_->data } @$pips ]), "\n";
21 return;
22 }
23  
24 if (!@$pips) {
25 print "No primary IPs found.\n";
26 return;
27 }
28  
29 printf "%-8s %-20s %-6s %-18s %-12s %-10s\n", 'ID', 'NAME', 'TYPE', 'IP', 'DATACENTER', 'ASSIGNEE';
30 printf "%-8s %-20s %-6s %-18s %-12s %-10s\n", '-' x 8, '-' x 20, '-' x 6, '-' x 18, '-' x 12, '-' x 10;
31  
32 for my $pip (@$pips) {
33 printf "%-8s %-20s %-6s %-18s %-12s %-10s\n",
34 $pip->id,
35 $pip->name // '-',
36 $pip->type // '-',
37 $pip->ip // '-',
38 $pip->datacenter_name // '-',
39 $pip->assignee_id // '-';
40 }
41 }
42  
43 1;
44  
45 __END__