| 1 | package Kubernetes::REST::CLI; | ||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: CLI base class for Kubernetes::REST command-line tools | ||||||||||||||||||||||||||||||||
| 3 | 2 | our $VERSION = '1.110'; | |||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use MooX::Options; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use MooX::Cmd; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use JSON::MaybeXS; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | 2 | with 'Kubernetes::REST::CLI::Role::Connection'; | |||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | option namespace => ( | ||||||||||||||||||||||||||||||||
| 13 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 14 | format => 's', | ||||||||||||||||||||||||||||||||
| 15 | short => 'n', | ||||||||||||||||||||||||||||||||
| 16 | 9 | ▶ | default => sub { 'default' }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 17 | 2 | doc => 'Namespace for namespaced resources', | |||||||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | option output => ( | ||||||||||||||||||||||||||||||||
| 22 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 23 | format => 's', | ||||||||||||||||||||||||||||||||
| 24 | short => 'o', | ||||||||||||||||||||||||||||||||
| 25 | 9 | ▶ | default => sub { 'json' }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 26 | 2 | doc => 'Output format: json, yaml, name', | |||||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | has json => ( | ||||||||||||||||||||||||||||||||
| 31 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 32 | 9 | ▶ | default => sub { JSON::MaybeXS->new->pretty->canonical->utf8 }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 33 | 2 | ); | |||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||
| 36 | 6 | ▶ | sub format_output { | ||||||||||||||||||||||||||||||
|
Subroutine
format_output: called CC=17 SCAR=51.6
Pod
documented
| |||||||||||||||||||||||||||||||||
| 37 | 6 | my ($self, $result) = @_; | |||||||||||||||||||||||||||||||
| 38 | 6 | ▶ | return unless defined $result; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||
| 40 | 6 | my $format = $self->output; | |||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | 6 | ▶ | if ($format eq 'json') { | ||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||
| 43 | 6 | ▶ | my $data = ref($result) && $result->can('TO_JSON') ? $result->TO_JSON : $result; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $result and $result->can("TO_JSON")
MC/DC0%0/2
ref $result and $result->can("TO_JSON")
ref $result
$result->can("TO_JSON")
Truth table33%1/3
A and B
A= ref $resultB= $result->can("TO_JSON")
| |||||||||||||||||||||||||||||||||
| 44 | 6 | print $self->json->encode($data); | |||||||||||||||||||||||||||||||
| 45 | } elsif ($format eq 'yaml') { | ||||||||||||||||||||||||||||||||
| 46 | 0 | require YAML::XS; | |||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | my $data = ref($result) && $result->can('TO_JSON') ? $result->TO_JSON : $result; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $result and $result->can("TO_JSON")
MC/DC0%0/2
ref $result and $result->can("TO_JSON")
ref $result
$result->can("TO_JSON")
Truth table0%0/3
A and B
A= ref $resultB= $result->can("TO_JSON")
| |||||||||||||||||||||||||||||||||
| 48 | 0 | print YAML::XS::Dump($data); | |||||||||||||||||||||||||||||||
| 49 | } elsif ($format eq 'name') { | ||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if (ref($result) && $result->can('items')) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
ref $result and $result->can("items")
MC/DC0%0/2
ref $result and $result->can("items")
ref $result
$result->can("items")
Truth table0%0/3
A and B
A= ref $resultB= $result->can("items")
| |||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | for my $item (@{$result->items // []}) { | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$result->items // []
MC/DC0%0/1
$result->items // []
$result->items
Truth table0%0/2
A
A= $result->items
| |||||||||||||||||||||||||||||||||
| 52 | 0 | my $meta = $item->metadata; | |||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | my $ns = $meta->namespace ? $meta->namespace . '/' : ''; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 54 | 0 | print $ns, $meta->name, "\n"; | |||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||
| 56 | ▶ | } elsif (ref($result) && $result->can('metadata')) { | |||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $result and $result->can("metadata")
MC/DC0%0/2
ref $result and $result->can("metadata")
ref $result
$result->can("metadata")
Truth table0%0/3
A and B
A= ref $resultB= $result->can("metadata")
| |||||||||||||||||||||||||||||||||
| 57 | 0 | my $meta = $result->metadata; | |||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | my $ns = $meta->namespace ? $meta->namespace . '/' : ''; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 59 | 0 | print $ns, $meta->name, "\n"; | |||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||
| 61 | } else { | ||||||||||||||||||||||||||||||||
| 62 | 0 | require Data::Dumper; | |||||||||||||||||||||||||||||||
| 63 | 0 | print Data::Dumper::Dumper($result); | |||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | sub execute { | ||||||||||||||||||||||||||||||
|
Subroutine
execute: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 69 | 0 | my ($self, $args, $chain) = @_; | |||||||||||||||||||||||||||||||
| 70 | 0 | print "Usage: kube_client <command> [options]\n\n"; | |||||||||||||||||||||||||||||||
| 71 | 0 | print "Commands:\n"; | |||||||||||||||||||||||||||||||
| 72 | 0 | print " get <Kind> [name] Get resource(s)\n"; | |||||||||||||||||||||||||||||||
| 73 | 0 | print " create -f <file> Create resource from file\n"; | |||||||||||||||||||||||||||||||
| 74 | 0 | print " delete <Kind> <name> Delete resource\n"; | |||||||||||||||||||||||||||||||
| 75 | 0 | print " raw <Group> <Method> Raw API call\n"; | |||||||||||||||||||||||||||||||
| 76 | 0 | print "\nRun 'kube_client --help' for options.\n"; | |||||||||||||||||||||||||||||||
| 77 | 0 | print "See also: kube_watch <Kind> for live event streaming.\n"; | |||||||||||||||||||||||||||||||
| 78 | 0 | return 0; | |||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | 2 | 1; | |||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | __END__ | ||||||||||||||||||||||||||||||||