| 1 | package WWW::Hetzner::CLI::Cmd::Volume; | ||
| 2 | # ABSTRACT: Volume commands | ||
| 3 | |||
| 4 | our $VERSION = '0.100'; | ||
| 5 | |||
| 6 | use Moo; | ||
| 7 | use MooX::Cmd; | ||
| 8 | use MooX::Options usage_string => 'USAGE: hcloud.pl volume <command> [options]'; | ||
| 9 | use JSON::MaybeXS qw(encode_json); | ||
| 10 | |||
| 11 | sub execute { | ||
| 12 | my ($self, $args, $chain) = @_; | ||
| 13 | |||
| 14 | # Default to list | ||
| 15 | $self->_list($chain); | ||
| 16 | } | ||
| 17 | |||
| 18 | sub _list { | ||
| 19 | my ($self, $chain) = @_; | ||
| 20 | |||
| 21 | my $main = $chain->[0]; | ||
| 22 | my $cloud = $main->cloud; | ||
| 23 | |||
| 24 | my $volumes = $cloud->volumes->list; | ||
| 25 | |||
| 26 | if ($main->output eq 'json') { | ||
| 27 | print encode_json([map { $_->data } @$volumes]), "\n"; | ||
| 28 | return; | ||
| 29 | } | ||
| 30 | |||
| 31 | if (!@$volumes) { | ||
| 32 | print "No volumes found.\n"; | ||
| 33 | return; | ||
| 34 | } | ||
| 35 | |||
| 36 | printf "%-10s %-25s %-8s %-10s %-10s %s\n", | ||
| 37 | 'ID', 'NAME', 'SIZE', 'SERVER', 'LOCATION', 'STATUS'; | ||
| 38 | print "-" x 80, "\n"; | ||
| 39 | |||
| 40 | for my $v (@$volumes) { | ||
| 41 | printf "%-10s %-25s %-8s %-10s %-10s %s\n", | ||
| 42 | $v->id, | ||
| 43 | $v->name, | ||
| 44 | $v->size . ' GB', | ||
| 45 | $v->server // '-', | ||
| 46 | $v->location // '-', | ||
| 47 | $v->status; | ||
| 48 | } | ||
| 49 | } | ||
| 50 | |||
| 51 | 1; | ||
| 52 | |||
| 53 | __END__ |