| 1 | package App::Ordo::Command::Cal::Detach; | ||
| 2 | use Moo; | ||
| 3 | use Term::ANSIColor qw(colored); | ||
| 4 | use feature qw(say); | ||
| 5 | extends 'App::Ordo::Command::Base'; | ||
| 6 | |||
| 7 | sub name { "cal detach" } | ||
| 8 | sub summary { "Detach a calendar from a cluster" } | ||
| 9 | sub usage { "<calendar> <cluster-path>" } | ||
| 10 | |||
| 11 | sub option_spec { {} } | ||
| 12 | |||
| 13 | sub execute { | ||
| 14 | my ($self, $opt, $cal_name, $cluster_path) = @_; | ||
| 15 | |||
| 16 | unless ($cal_name && $cluster_path) { | ||
| 17 | say colored(["bold red"], "Usage: cal detach <calendar> <cluster-path>"); | ||
| 18 | return; | ||
| 19 | } | ||
| 20 | |||
| 21 | my $res = $self->api->call('update_cluster', { | ||
| 22 | name => $cluster_path, | ||
| 23 | cal_id => '', # empty string = detach | ||
| 24 | }); | ||
| 25 | |||
| 26 | if ($res->{success}) { | ||
| 27 | say colored(["bold green"], "Calendar '$cal_name' detached from cluster '$cluster_path'"); | ||
| 28 | } else { | ||
| 29 | say colored(["bold red"], "Failed: " . ($res->{message} || 'not found')); | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | 1; |