Ordo/Command/Cal/Cron/Add.pm untested

filter: Statementstmt 0.0% 0 / 29 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 54 CC 3 SCAR 16.1
CC
3
Cov
0%
execute
12.0
name
2.0
summary
2.0
CRAP 5.0
1 package App::Ordo::Command::Cal::Cron::Add;
2 use Moo;
3 use feature qw(say);
4 extends 'App::Ordo::Command::Base';
5 use Term::ANSIColor qw(colored);
6  
7 sub name { "cal cron add" }
8 sub summary { "Add a cron expression to a calendar" }
9 sub usage { "<calendar> \"<cron expression\" [--description \"text\"]" }
10  
11 sub option_spec {
12 return {
13 'description=s' => 'Description for this cron',
14 };
15 }
16  
17 sub execute {
18 my ($self, $opt, $cal_name, $cron_expr) = @_;
19  
20 unless ($cal_name && $cron_expr) {
21 say colored(["bold red"], "Usage: cal cron add <calendar> \"<cron>\" [--description \"...\"]");
22 return;
23 }
24  
25 my $res = $self->api->call('create_cron', {
26 cal => $cal_name,
27 name => $cron_expr,
28 description => $opt->{description},
29 });
30  
31 if ($res->{success}) {
32 say colored(["bold green"], "Cron '$cron_expr' added to calendar '$cal_name'");
33 } else {
34 say colored(["bold red"], "Failed: " . ($res->{message} || 'calendar not found'));
35 }
36 }
37  
38 1;