| 1 | package App::Ordo::Command::Cal::Create; | ||
| 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 create" } | ||
| 9 | sub summary { "Create a new calendar" } | ||
| 10 | sub usage { "<name> [--desc \"description\"]" } | ||
| 11 | |||
| 12 | sub option_spec { | ||
| 13 | return { | ||
| 14 | 'description=s' => 'Description for the calendar', | ||
| 15 | # No positional options in spec — name is taken from @args | ||
| 16 | }; | ||
| 17 | } | ||
| 18 | |||
| 19 | sub execute { | ||
| 20 | my ($self, $opt, $name) = @_; | ||
| 21 | |||
| 22 | unless ($name) { | ||
| 23 | say colored(["bold red"], "Error: calendar name is required"); | ||
| 24 | $self->show_help; | ||
| 25 | return; | ||
| 26 | } | ||
| 27 | |||
| 28 | my $res = $self->api->call('create_cal', { | ||
| 29 | name => $name, | ||
| 30 | tz => $self->api->tz, | ||
| 31 | description => $opt->{description}, | ||
| 32 | }); | ||
| 33 | |||
| 34 | if ($res->{success}) { | ||
| 35 | say colored(["bold green"], "Calendar '$name' created successfully"); | ||
| 36 | } else { | ||
| 37 | say colored(["bold red"], "Failed to create calendar: " . ($res->{message} || 'unknown error')); | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | 1; |