Ordo/Command/Cluster/Delete.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 65 CC 5 SCAR 25.5
CC
5
Cov
0%
execute
30.0
name
2.0
summary
2.0
CRAP 12.8
1 package App::Ordo::Command::Cluster::Delete;
2 use Moo;
3 use feature qw(say);
4 use Term::ANSIColor qw(colored);
5 extends 'App::Ordo::Command::Base';
6  
7 use App::Ordo qw($CURRENT_PATH);
8  
9 sub name { "cluster delete" }
10 sub summary { "Delete a cluster and all its jobs" }
11 sub usage { "<path>" }
12  
13 sub option_spec {
14 return {
15 'force|f' => 'Force delete even if jobs are running',
16 };
17 }
18  
19 sub execute {
20 my ($self, $opt, $path) = @_;
21  
22 unless ($path) {
23 say colored(["bold red"], "Usage: cluster delete <path> [--force]");
24 return;
25 }
26  
27 #my $full_path = $path =~ m|^/| ? $path : "$CURRENT_PATH/$path";
28 #$full_path =~ s|//+|/|g;
29  
30 my $payload = { name => $path };
31 $payload->{force} = 1 if $opt->{force};
32  
33 my $res = $self->api->call('delete_cluster', $payload);
34  
35 if ($res->{success}) {
36 say colored(["bold green"], "Cluster and all jobs deleted");
37 } else {
38 say colored(["bold red"], "Failed: " . ($res->{message} || 'unknown error'));
39 say "Hint: use --force if jobs are running" if $res->{message} && $res->{message} =~ /running|active/i;
40 }
41 }
42  
43 1;