summaryrefslogtreecommitdiffstats
path: root/lib/App/Hiveminder/Command/Create.pm
blob: fd254298b2a5b97206f34eb1ab98d97988ab7d77 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/perl
package App::Hiveminder::Command::Create;
use Moose;
use App::Hiveminder::Utils qw/get_text_from_editor_or_cmdline display_tasks
                              update_tasks/;
extends 'App::Hiveminder::Command';

=head2 NAME

App::Hiveminder::Command::Create - Create a new task

=cut

sub command_names { qw/create c/ }

sub command {
    my $self = shift;

    my $text = get_text_from_editor_or_cmdline(@_);
    return '' if $text eq '';
    my @text = split "\n", $text;

    my $task = $self->hm->create_task(shift @text);
    my $ret = display_tasks($self->hm, $task);

    if (@text > 0) {
        $ret = display_tasks($self->hm,
            @{ update_tasks($self->hm, [$self->hm->id2loc($task->{id})],
                            sub { (description => (join "\n", @text)) }) });
    }

    return $ret;
}

__PACKAGE__->meta()->make_immutable();
1;