| 1 | package App::JobLog::Command::tags; | ||
| 2 | $App::JobLog::Command::tags::VERSION = '1.042'; | ||
| 3 | # ABSTRACT: show what tags you have used | ||
| 4 | |||
| 5 | use App::JobLog -command; | ||
| 6 | use Modern::Perl; | ||
| 7 | use Class::Autouse qw(App::JobLog::Log); | ||
| 8 | use autouse 'App::JobLog::TimeGrammar' => qw(parse); | ||
| 9 | use autouse 'Getopt::Long::Descriptive' => qw(prog_name); | ||
| 10 | |||
| 11 | sub execute { | ||
| 12 | my ( $self, $opt, $args ) = @_; | ||
| 13 | |||
| 14 | my $events = []; | ||
| 15 | eval { | ||
| 16 | if (@$args) | ||
| 17 | { | ||
| 18 | my ( $start, $end ) = parse( join( ' ', @$args ) ); | ||
| 19 | $events = App::JobLog::Log->new->find_events( $start, $end ) | ||
| 20 | unless $opt->notes; | ||
| 21 | push @$events, | ||
| 22 | @{ App::JobLog::Log->new->find_notes( $start, $end ) } | ||
| 23 | unless !( $opt->notes || $opt->all ); | ||
| 24 | } | ||
| 25 | else { | ||
| 26 | my $method = 'all_events'; | ||
| 27 | if ( $opt->notes ) { | ||
| 28 | $method = 'all_notes'; | ||
| 29 | } | ||
| 30 | elsif ( $opt->all ) { | ||
| 31 | $method = 'all_taglines'; | ||
| 32 | } | ||
| 33 | $events = App::JobLog::Log->new->$method; | ||
| 34 | } | ||
| 35 | }; | ||
| 36 | $self->usage_error($@) if $@; | ||
| 37 | my %tags; | ||
| 38 | for my $e (@$events) { | ||
| 39 | $tags{$_} = 1 for @{ $e->tags }; | ||
| 40 | } | ||
| 41 | if (%tags) { | ||
| 42 | print "\n"; | ||
| 43 | say $_ for sort keys %tags; | ||
| 44 | print "\n"; | ||
| 45 | } | ||
| 46 | else { | ||
| 47 | say 'no tags in log'; | ||
| 48 | } | ||
| 49 | } | ||
| 50 | |||
| 51 | sub usage_desc { '%c ' . __PACKAGE__->name . ' %o [date or date range]' } | ||
| 52 | |||
| 53 | sub abstract { | ||
| 54 | 'list tags employed in log or some subrange thereof'; | ||
| 55 | } | ||
| 56 | |||
| 57 | sub full_description { | ||
| 58 | <<END | ||
| 59 | List the tags used to categorize tasks or notes in the log or in a specified range of dates. This allows one to | ||
| 60 | explore the categorical structure of tasks and notes. By default only tags associated with notes are listed. | ||
| 61 | |||
| 62 | The date expressions understood are the same as those understood by the C<summary> command. | ||
| 63 | END | ||
| 64 | } | ||
| 65 | |||
| 66 | sub options { | ||
| 67 | return ( | ||
| 68 | [ | ||
| 69 | "Use '@{[prog_name]} help " | ||
| 70 | . __PACKAGE__->name | ||
| 71 | . '\' to see full details.' | ||
| 72 | ], | ||
| 73 | [ 'notes|n', 'only list tags used on notes' ], | ||
| 74 | [ 'all|a', 'list tags for both notes and tasks' ], | ||
| 75 | ); | ||
| 76 | } | ||
| 77 | |||
| 78 | sub validate { | ||
| 79 | my ( $self, $opt, $args ) = @_; | ||
| 80 | $self->usage_error('--notes conflicts will --all') | ||
| 81 | if $opt->notes && $opt->all; | ||
| 82 | } | ||
| 83 | |||
| 84 | 1; | ||
| 85 | |||
| 86 | __END__ |