« lib/WWW/Hetzner/CLI/Cmd/LoadBalancer/Cmd/List.pm
↑ Summary
lib/WWW/Hetzner/CLI/Cmd/StorageBox/Cmd/Snapshot.pm »
| 1 | package WWW::Hetzner::CLI::Cmd::StorageBox::Cmd::Snapshot::Cmd::RemoveLabel; | ||||||||||||
| 2 | # ABSTRACT: Remove a label from a Storage Box snapshot | ||||||||||||
| 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 snapshot remove-label <storage-box> <snapshot> <key>'; | ||||||||||
|
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 | 1 | ▶ | use WWW::Hetzner::Storage::API::Snapshots; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | |||||||||||||
| 12 | |||||||||||||
| 13 | 1 | ▶ | sub execute { | ||||||||||
|
Subroutine
execute: called CC=10 SCAR=25.2
Pod
undocumented
| |||||||||||||
| 14 | 1 | my ($self, $args, $chain) = @_; | |||||||||||
| 15 | 1 | ▶ | my $id = $args->[0] or die "Usage: hcloud.pl storage-box snapshot remove-label <storage-box> <snapshot> <key>\n"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 16 | 1 | ▶ | my $snap = $args->[1] or die "Usage: hcloud.pl storage-box snapshot remove-label <storage-box> <snapshot> <key>\n"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 17 | 1 | ▶ | my $key = $args->[2] or die "Usage: hcloud.pl storage-box snapshot remove-label <storage-box> <snapshot> <key>\n"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 18 | |||||||||||||
| 19 | 1 | my $main = $chain->[0]; | |||||||||||
| 20 | 1 | my $snapshots = WWW::Hetzner::Storage::API::Snapshots->new( | |||||||||||
| 21 | client => $main->storage, | ||||||||||||
| 22 | storage_box_id => $id, | ||||||||||||
| 23 | ); | ||||||||||||
| 24 | 1 | my $snapshot = $snapshots->get($snap); | |||||||||||
| 25 | 1 | ▶ | my %labels = %{ $snapshot->labels // {} }; | ||||||||||
|
Condition50%1/2
$snapshot->labels // {}
MC/DC0%0/1
$snapshot->labels // {}
$snapshot->labels
Truth table50%1/2
A
A= $snapshot->labels
| |||||||||||||
| 26 | 1 | delete $labels{$key}; | |||||||||||
| 27 | 1 | my $updated = $snapshots->update($snap, labels => \%labels); | |||||||||||
| 28 | |||||||||||||
| 29 | 1 | ▶ | if ($main->output eq 'json') { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 30 | 0 | print encode_json($updated->data), "\n"; | |||||||||||
| 31 | 0 | return; | |||||||||||
| 32 | } | ||||||||||||
| 33 | |||||||||||||
| 34 | 1 | print "Snapshot labels updated:\n"; | |||||||||||
| 35 | 1 | printf " ID: %s\n", $updated->id; | |||||||||||
| 36 | 1 | ▶ | printf " Name: %s\n", $updated->name // '-'; | ||||||||||
|
Condition50%1/2
$updated->name // "-"
MC/DC0%0/1
$updated->name // "-"
$updated->name
Truth table50%1/2
A
A= $updated->name
| |||||||||||||
| 37 | 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
| |||||||||||||
| 38 | 1 | ▶ | if (%$new_labels) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 39 | 1 | print " Labels:\n"; | |||||||||||
| 40 | 1 | printf " %s: %s\n", $_, $new_labels->{$_} for sort keys %$new_labels; | |||||||||||
| 41 | } else { | ||||||||||||
| 42 | 0 | print " Labels: (none)\n"; | |||||||||||
| 43 | } | ||||||||||||
| 44 | } | ||||||||||||
| 45 | |||||||||||||
| 46 | 1 | 1; | |||||||||||
| 47 | |||||||||||||
| 48 | __END__ | ||||||||||||