« lib/WWW/Hetzner/Robot/CLI/Cmd/Reset.pm
↑ Summary
lib/WWW/Hetzner/Robot/CLI/Cmd/Server/Cmd/List.pm »
| 1 | package WWW::Hetzner::Robot::CLI::Cmd::Server; | ||
| 2 | # ABSTRACT: Robot server commands | ||
| 3 | |||
| 4 | our $VERSION = '0.100'; | ||
| 5 | |||
| 6 | use Moo; | ||
| 7 | use MooX::Cmd; | ||
| 8 | use MooX::Options usage_string => 'USAGE: hrobot.pl server [list|describe] [options]'; | ||
| 9 | |||
| 10 | |||
| 11 | sub execute { | ||
| 12 | my ($self, $args, $chain) = @_; | ||
| 13 | my $root = $chain->[0]; | ||
| 14 | my $robot = $root->robot; | ||
| 15 | |||
| 16 | # Default: list servers | ||
| 17 | my $servers = $robot->servers->list; | ||
| 18 | |||
| 19 | if ($root->output eq 'json') { | ||
| 20 | require JSON::MaybeXS; | ||
| 21 | print JSON::MaybeXS::encode_json([map { +{ | ||
| 22 | server_number => $_->server_number, | ||
| 23 | server_name => $_->server_name, | ||
| 24 | server_ip => $_->server_ip, | ||
| 25 | product => $_->product, | ||
| 26 | dc => $_->dc, | ||
| 27 | status => $_->status, | ||
| 28 | } } @$servers]); | ||
| 29 | print "\n"; | ||
| 30 | } else { | ||
| 31 | printf "%-12s %-20s %-15s %-20s %s\n", | ||
| 32 | 'NUMBER', 'NAME', 'IP', 'PRODUCT', 'DC'; | ||
| 33 | for my $s (@$servers) { | ||
| 34 | printf "%-12s %-20s %-15s %-20s %s\n", | ||
| 35 | $s->server_number // '', | ||
| 36 | $s->server_name // '', | ||
| 37 | $s->server_ip // '', | ||
| 38 | $s->product // '', | ||
| 39 | $s->dc // ''; | ||
| 40 | } | ||
| 41 | } | ||
| 42 | } | ||
| 43 | |||
| 44 | 1; | ||
| 45 | |||
| 46 | __END__ |