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

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 8 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 49 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::LoadBalancer::Cmd::List;
2 # ABSTRACT: List load balancers
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 load-balancer 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 $lbs = $cloud->load_balancers->list;
18  
19 if ($main->output eq 'json') {
20 print encode_json([ map { $_->data } @$lbs ]), "\n";
21 return;
22 }
23  
24 if (!@$lbs) {
25 print "No load balancers found.\n";
26 return;
27 }
28  
29 printf "%-8s %-25s %-10s %-18s %-10s\n", 'ID', 'NAME', 'TYPE', 'IPV4', 'LOCATION';
30 printf "%-8s %-25s %-10s %-18s %-10s\n", '-' x 8, '-' x 25, '-' x 10, '-' x 18, '-' x 10;
31  
32 for my $lb (@$lbs) {
33 printf "%-8s %-25s %-10s %-18s %-10s\n",
34 $lb->id,
35 $lb->name // '-',
36 $lb->type_name // '-',
37 $lb->ipv4 // '-',
38 $lb->location_name // '-';
39 }
40 }
41  
42 1;
43  
44 __END__