lib/WWW/Hetzner/CLI/Cmd/Server/Cmd/List.pm

filter: Statementstmt 84.3% 27 / 32 Branchbran 66.6% 4 / 6 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 73.5% 39 / 53 CC 8 SCAR 20.0
CC
8
Cov
77%
execute
10.6
BEGIN
1.0
BEGIN
1.0
CRAP 7.4
« lib/WWW/Hetzner/CLI/Cmd/Zone/Cmd/List.pm ↑ Summary lib/WWW/Hetzner/Cloud/API/FloatingIPs.pm »
1 package WWW::Hetzner::CLI::Cmd::Server::Cmd::List;
2 # ABSTRACT: List servers
3  
4 2 our $VERSION = '0.102';
5  
6 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use MooX::Cmd;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use MooX::Options usage_string => 'USAGE: hcloud.pl server list [options]';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use JSON::MaybeXS qw(encode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 option selector => (
12 is => 'ro',
13 format => 's',
14 short => 'l',
15 doc => 'Label selector (e.g., env=prod)',
16 );
17  
18 2 ▶sub execute {
Subroutine execute: called CC=8 SCAR=23.6
Pod undocumented
19 2 my ($self, $args, $chain) = @_;
20  
21 2 my $main = $chain->[0];
22 2 my $cloud = $main->cloud;
23  
24 2 my %params;
25 2 ▶ $params{label_selector} = $self->selector if $self->selector;
Branch: 1 branch
BranchTrueFalseTotal
if $self->selector 1 1 2
26  
27 2 my $servers = $cloud->servers->list_all(%params);
28  
29 2 ▶ if ($main->output eq 'json') {
Branch: 1 branch
BranchTrueFalseTotal
if ($main->output eq "json") 0 2 2
30 0 print encode_json([map { $_->data } @$servers]), "\n";
31 0 return;
32 }
33  
34 2 ▶ if (!@$servers) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$servers) 0 2 2
35 0 print "No servers found.\n";
36 0 return;
37 }
38  
39 2 printf "%-10s %-25s %-12s %-16s %-10s %s\n",
40 'ID', 'NAME', 'STATUS', 'IPV4', 'TYPE', 'LOCATION';
41 2 print "-" x 90, "\n";
42  
43 2 for my $s (@$servers) {
44 2 ▶ printf "%-10s %-25s %-12s %-16s %-10s %s\n",
Condition50%3/6
$s->ipv4 // "-"
l!l
20
$s->server_type // "-"
l!l
20
$s->location // "-"
l!l
20
MC/DC0%0/1
$s->ipv4 // "-"
$s->ipv4
MC/DC0%0/1
$s->server_type // "-"
$s->server_type
MC/DC0%0/1
$s->location // "-"
$s->location
Truth table50%1/2
A
A= $s->ipv4
Aresult
11
00
Truth table50%1/2
A
A= $s->server_type
Aresult
11
00
Truth table50%1/2
A
A= $s->location
Aresult
11
00
45 $s->id,
46 $s->name,
47 $s->status,
48 $s->ipv4 // '-',
49 $s->server_type // '-',
50 $s->location // '-';
51 }
52 }
53  
54 2 1;
55  
56 __END__
« lib/WWW/Hetzner/CLI/Cmd/Zone/Cmd/List.pm ↑ Summary lib/WWW/Hetzner/Cloud/API/FloatingIPs.pm »