| 1 | package WWW::Hetzner::CLI::Cmd::FloatingIp::Cmd::List; | ||
| 2 | # ABSTRACT: List floating IPs | ||
| 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 floating-ip 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 $fips = $cloud->floating_ips->list; | ||
| 18 | |||
| 19 | if ($main->output eq 'json') { | ||
| 20 | print encode_json([ map { $_->data } @$fips ]), "\n"; | ||
| 21 | return; | ||
| 22 | } | ||
| 23 | |||
| 24 | if (!@$fips) { | ||
| 25 | print "No floating IPs found.\n"; | ||
| 26 | return; | ||
| 27 | } | ||
| 28 | |||
| 29 | printf "%-8s %-20s %-6s %-18s %-10s %-10s\n", 'ID', 'NAME', 'TYPE', 'IP', 'LOCATION', 'SERVER'; | ||
| 30 | printf "%-8s %-20s %-6s %-18s %-10s %-10s\n", '-' x 8, '-' x 20, '-' x 6, '-' x 18, '-' x 10, '-' x 10; | ||
| 31 | |||
| 32 | for my $fip (@$fips) { | ||
| 33 | printf "%-8s %-20s %-6s %-18s %-10s %-10s\n", | ||
| 34 | $fip->id, | ||
| 35 | $fip->name // '-', | ||
| 36 | $fip->type // '-', | ||
| 37 | $fip->ip // '-', | ||
| 38 | $fip->location // '-', | ||
| 39 | $fip->server // '-'; | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | 1; | ||
| 44 | |||
| 45 | __END__ |