| 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
| |||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | 2 | my $servers = $cloud->servers->list_all(%params); | |||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | if ($main->output eq 'json') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 30 | 0 | print encode_json([map { $_->data } @$servers]), "\n"; | |||||||||||||||||||||||||||||||
| 31 | 0 | return; | |||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | 2 | ▶ | if (!@$servers) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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 // "-"
$s->server_type // "-"
$s->location // "-"
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
Truth table50%1/2
A
A= $s->server_type
Truth table50%1/2
A
A= $s->location
| |||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||