| 1 | package WWW::Hetzner::Robot::CLI::Cmd::Key; | ||
| 2 | # ABSTRACT: Robot SSH key commands | ||
| 3 | |||
| 4 | our $VERSION = '0.100'; | ||
| 5 | |||
| 6 | use Moo; | ||
| 7 | use MooX::Cmd; | ||
| 8 | use MooX::Options usage_string => 'USAGE: hrobot.pl key [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 keys | ||
| 17 | my $keys = $robot->keys->list; | ||
| 18 | |||
| 19 | if ($root->output eq 'json') { | ||
| 20 | require JSON::MaybeXS; | ||
| 21 | print JSON::MaybeXS::encode_json([map { +{ | ||
| 22 | name => $_->name, | ||
| 23 | fingerprint => $_->fingerprint, | ||
| 24 | type => $_->type, | ||
| 25 | size => $_->size, | ||
| 26 | } } @$keys]); | ||
| 27 | print "\n"; | ||
| 28 | } else { | ||
| 29 | printf "%-20s %-50s %-10s %s\n", 'NAME', 'FINGERPRINT', 'TYPE', 'SIZE'; | ||
| 30 | for my $k (@$keys) { | ||
| 31 | printf "%-20s %-50s %-10s %s\n", | ||
| 32 | $k->name // '', | ||
| 33 | $k->fingerprint // '', | ||
| 34 | $k->type // '', | ||
| 35 | $k->size // ''; | ||
| 36 | } | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 40 | 1; | ||
| 41 | |||
| 42 | __END__ |