« lib/WWW/Hetzner/CLI/Cmd/Record/Cmd/Describe.pm
↑ Summary
lib/WWW/Hetzner/CLI/Cmd/Volume/Cmd/Create.pm »
| 1 | package WWW::Hetzner::CLI::Cmd::Sshkey::Cmd::Describe; | ||
| 2 | # ABSTRACT: Describe an SSH key | ||
| 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 sshkey describe <id>'; | ||
| 9 | use JSON::MaybeXS qw(encode_json); | ||
| 10 | |||
| 11 | sub execute { | ||
| 12 | my ($self, $args, $chain) = @_; | ||
| 13 | my $id = $args->[0] or die "Usage: hcloud.pl sshkey describe <id>\n"; | ||
| 14 | |||
| 15 | my $main = $chain->[0]; | ||
| 16 | my $cloud = $main->cloud; | ||
| 17 | |||
| 18 | my $key = $cloud->ssh_keys->get($id); | ||
| 19 | |||
| 20 | if ($main->output eq 'json') { | ||
| 21 | print encode_json($key->data), "\n"; | ||
| 22 | } else { | ||
| 23 | printf "ID: %s\n", $key->id; | ||
| 24 | printf "Name: %s\n", $key->name; | ||
| 25 | printf "Fingerprint: %s\n", $key->fingerprint; | ||
| 26 | printf "Created: %s\n", $key->created // '-'; | ||
| 27 | printf "Public Key:\n%s\n", $key->public_key; | ||
| 28 | } | ||
| 29 | } | ||
| 30 | |||
| 31 | 1; | ||
| 32 | |||
| 33 | __END__ |