summaryrefslogtreecommitdiffstats
path: root/lib/App/Hiveminder/Command/Create.pm
blob: 6295a520f8dc1b8833d2b9656de13f7a497d3ae3 (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
#!/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';

sub command {
    my ($self, $args) = @_;
    $args = join " ", @$args;

    my $text = get_text_from_editor_or_cmdline($args);
    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;