| 1 | package WWW::Hetzner::CLI::Cmd::StorageBox::Cmd::AddLabel; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Add a label to a Storage Box | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | our $VERSION = '0.102'; | |||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use MooX::Cmd; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use MooX::Options protect_argv => 0, usage_string => 'USAGE: hcloud.pl storage-box add-label <storage-box> <key>=<value>'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use JSON::MaybeXS qw(encode_json); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | sub execute { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
execute: called CC=11 SCAR=27.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | my ($self, $args, $chain) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | my $id = $args->[0] or die "Usage: hcloud.pl storage-box add-label <storage-box> <key>=<value>\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | my $label = $args->[1] or die "Usage: hcloud.pl storage-box add-label <storage-box> <key>=<value>\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | my ($key, $value) = split /=/, $label, 2; | |||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | die "Label must be key=value\n" unless defined $key && length $key && defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $key and length $key and defined $value
defined $key and length $key
MC/DC0%0/3
defined $key and length $key and defined $value
defined $key
length $key
defined $value
Truth table25%1/4
A and B and C
A= defined $keyB= length $keyC= defined $value
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | my $main = $chain->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | my $box = $main->storage->storage_boxes->get($id); | |||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | my %labels = %{ $box->labels // {} }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$box->labels // {}
MC/DC0%0/1
$box->labels // {}
$box->labels
Truth table50%1/2
A
A= $box->labels
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | $labels{$key} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | my $updated = $main->storage->storage_boxes->update($id, labels => \%labels); | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | if ($main->output eq 'json') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | print encode_json($updated->data), "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | print "Storage Box labels updated:\n"; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | printf " ID: %s\n", $updated->id; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | printf " Name: %s\n", $updated->name; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | my $new_labels = $updated->labels // {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$updated->labels // {}
MC/DC0%0/1
$updated->labels // {}
$updated->labels
Truth table50%1/2
A
A= $updated->labels
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | ▶ | if (%$new_labels) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | print " Labels:\n"; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | printf " %s: %s\n", $_, $new_labels->{$_} for sort keys %$new_labels; | |||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | __END__ | ||||||||||||||||||||||||||||||||||||||||||