| 1 | package App::Ordo::Command::Cal::Cron::Delete; | ||
| 2 | use Moo; | ||
| 3 | use feature qw(say); | ||
| 4 | extends 'App::Ordo::Command::Base'; | ||
| 5 | |||
| 6 | use Term::ANSIColor qw(colored); | ||
| 7 | |||
| 8 | sub name { "cal cron delete" } | ||
| 9 | sub summary { "Delete a cron expression from a calendar" } | ||
| 10 | sub usage { "<cron-id>" } | ||
| 11 | sub aliases { ['cal cron rm'] } | ||
| 12 | |||
| 13 | sub option_spec { | ||
| 14 | return {}; | ||
| 15 | } | ||
| 16 | |||
| 17 | sub execute { | ||
| 18 | my ( $self, $opt, $cron_id ) = @_; | ||
| 19 | |||
| 20 | unless ( $cron_id && $cron_id =~ /^\d+$/ ) { | ||
| 21 | say colored( ["bold red"], "Usage: cal cron delete <cron-id>" ); | ||
| 22 | say "Example: cal cron delete 13"; | ||
| 23 | return; | ||
| 24 | } | ||
| 25 | |||
| 26 | my $payload = { | ||
| 27 | |||
| 28 | # cal => $cal_name, | ||
| 29 | id => $cron_id, | ||
| 30 | }; | ||
| 31 | $payload->{force} = 1 if $opt->{force}; | ||
| 32 | |||
| 33 | my $res = $self->api->call( 'delete_cron', $payload ); | ||
| 34 | |||
| 35 | if ( $res->{success} ) { | ||
| 36 | my $name = $res->{cal}; | ||
| 37 | my $message = "Cron ID $cron_id removed from calendar"; | ||
| 38 | $message .= " $res->{cal}" if $res->{cal}; | ||
| 39 | say colored( ["bold green"], $message ); | ||
| 40 | } | ||
| 41 | else { | ||
| 42 | say colored( ["bold red"], "Failed to delete cron: " . ( $res->{message} || 'unknown error' ) ); | ||
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 46 | 1; |