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

filter: Statementstmt 94.4% 34 / 36 Branchbran 62.5% 5 / 8 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 80.0% 48 / 60 CC 9 SCAR 19.4
CC
9
Cov
84%
_list
10.3
BEGIN
1.0
BEGIN
1.0
CRAP 7.0
« lib/WWW/Hetzner/CLI/Cmd/StorageBox/Cmd/UpdateAccessSettings.pm ↑ Summary lib/WWW/Hetzner/CLI/Cmd/Network/Cmd/List.pm »
1 package WWW::Hetzner::CLI::Cmd::Server;
2 # ABSTRACT: Server commands
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 <command> [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  
12 2 ▶sub execute {
Subroutine execute: called CC=1 SCAR=0.0
Pod undocumented
13 2 my ($self, $args, $chain) = @_;
14  
15 # Default to list
16 2 $self->_list($chain);
17 }
18  
19 2 option selector => (
20 is => 'ro',
21 format => 's',
22 short => 'l',
23 doc => 'Label selector (e.g., env=prod)',
24 );
25  
26 2 option name => (
27 is => 'ro',
28 format => 's',
29 short => 'n',
30 doc => 'Filter by name',
31 );
32  
33 2 ▶sub _list {
Subroutine _list: called CC=9 SCAR=23.3
34 2 my ($self, $chain) = @_;
35  
36 2 my $main = $chain->[0];
37 2 my $cloud = $main->cloud;
38  
39 2 my %params;
40 2 ▶ $params{label_selector} = $self->selector if $self->selector;
Branch: 1 branch
BranchTrueFalseTotal
if $self->selector 0 2 2
41 2 ▶ $params{name} = $self->name if $self->name;
Branch: 1 branch
BranchTrueFalseTotal
if $self->name 0 2 2
42  
43 2 my $servers = $cloud->servers->list_all(%params);
44  
45 2 ▶ if ($main->output eq 'json') {
Branch: 1 branch
BranchTrueFalseTotal
if ($main->output eq "json") 1 1 2
46 1 print encode_json([ map { $_->data } @$servers ]), "\n";
47 1 return;
48 }
49  
50 # Table output
51 1 ▶ if (!@$servers) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$servers) 0 1 1
52 0 print "No servers found.\n";
53 0 return;
54 }
55  
56 1 printf "%-10s %-25s %-12s %-16s %-10s %s\n",
57 'ID', 'NAME', 'STATUS', 'IPV4', 'TYPE', 'LOCATION';
58 1 print "-" x 90, "\n";
59  
60 1 for my $s (@$servers) {
61 1 ▶ printf "%-10s %-25s %-12s %-16s %-10s %s\n",
Condition50%3/6
$s->ipv4 // "-"
l!l
10
$s->server_type // "-"
l!l
10
$s->location // "-"
l!l
10
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
62 $s->id,
63 $s->name,
64 $s->status,
65 $s->ipv4 // '-',
66 $s->server_type // '-',
67 $s->location // '-';
68 }
69 }
70  
71  
72 2 1.
73  
74 __END__
« lib/WWW/Hetzner/CLI/Cmd/StorageBox/Cmd/UpdateAccessSettings.pm ↑ Summary lib/WWW/Hetzner/CLI/Cmd/Network/Cmd/List.pm »