| 1 | package WWW::Hetzner::CLI::Cmd::Record::Cmd::Describe; | ||
| 2 | # ABSTRACT: Describe a DNS record | ||
| 3 | |||
| 4 | our $VERSION = '0.100'; | ||
| 5 | |||
| 6 | use Moo; | ||
| 7 | use MooX::Cmd; | ||
| 8 | use MooX::Options usage_string => 'USAGE: hcloud.pl record describe --zone <zone-id> --name <name> --type <type>'; | ||
| 9 | use JSON::MaybeXS qw(encode_json); | ||
| 10 | |||
| 11 | option zone => ( | ||
| 12 | is => 'ro', | ||
| 13 | format => 's', | ||
| 14 | short => 'z', | ||
| 15 | required => 1, | ||
| 16 | doc => 'Zone ID', | ||
| 17 | ); | ||
| 18 | |||
| 19 | option name => ( | ||
| 20 | is => 'ro', | ||
| 21 | format => 's', | ||
| 22 | short => 'n', | ||
| 23 | required => 1, | ||
| 24 | doc => 'Record name', | ||
| 25 | ); | ||
| 26 | |||
| 27 | option type => ( | ||
| 28 | is => 'ro', | ||
| 29 | format => 's', | ||
| 30 | short => 't', | ||
| 31 | required => 1, | ||
| 32 | doc => 'Record type (A, AAAA, CNAME, MX, TXT, etc.)', | ||
| 33 | ); | ||
| 34 | |||
| 35 | sub execute { | ||
| 36 | my ($self, $args, $chain) = @_; | ||
| 37 | |||
| 38 | my $main = $chain->[0]; | ||
| 39 | my $cloud = $main->cloud; | ||
| 40 | |||
| 41 | my $rrsets = $cloud->zones->rrsets($self->zone); | ||
| 42 | my $record = $rrsets->get($self->name, uc($self->type)); | ||
| 43 | |||
| 44 | if ($main->output eq 'json') { | ||
| 45 | print encode_json($record->data), "\n"; | ||
| 46 | return; | ||
| 47 | } | ||
| 48 | |||
| 49 | print "Record:\n"; | ||
| 50 | printf " Name: %s\n", $record->name; | ||
| 51 | printf " Type: %s\n", $record->type; | ||
| 52 | printf " TTL: %s\n", $record->ttl // '-'; | ||
| 53 | print " Values:\n"; | ||
| 54 | for my $v (@{$record->records}) { | ||
| 55 | print " - $v->{value}\n"; | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | 1; | ||
| 60 | |||
| 61 | __END__ |