| 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; |