lib/WWW/Hetzner/CLI/Cmd/Certificate/Cmd/List.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 8 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 54 CC 4 SCAR 24.0
CC
4
Cov
0%
execute
20.0
BEGIN
2.0
BEGIN
2.0
CRAP 11.0
1 package WWW::Hetzner::CLI::Cmd::Certificate::Cmd::List;
2 # ABSTRACT: List certificates
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 certificate 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 $certs = $cloud->certificates->list;
18  
19 if ($main->output eq 'json') {
20 print encode_json([ map { $_->data } @$certs ]), "\n";
21 return;
22 }
23  
24 if (!@$certs) {
25 print "No certificates found.\n";
26 return;
27 }
28  
29 printf "%-8s %-30s %-10s %-30s\n", 'ID', 'NAME', 'TYPE', 'DOMAINS';
30 printf "%-8s %-30s %-10s %-30s\n", '-' x 8, '-' x 30, '-' x 10, '-' x 30;
31  
32 for my $c (@$certs) {
33 my $domains = join(', ', @{$c->domain_names // []}) || '-';
34 $domains = substr($domains, 0, 27) . '...' if length($domains) > 30;
35 printf "%-8s %-30s %-10s %-30s\n",
36 $c->id, $c->name // '-', $c->type // '-', $domains;
37 }
38 }
39  
40 1;
41  
42 __END__