| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::GitGot::Command::tag; | 
| 2 |  |  |  |  |  |  | our $AUTHORITY = 'cpan:GENEHACK'; | 
| 3 |  |  |  |  |  |  | $App::GitGot::Command::tag::VERSION = '1.336'; | 
| 4 |  |  |  |  |  |  | # ABSTRACT: list/add/remove tags for the current repository | 
| 5 | 15 |  |  | 15 |  | 7766 | use 5.014; | 
|  | 15 |  |  |  |  | 47 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 15 |  |  | 15 |  | 69 | use Moo; | 
|  | 15 |  |  |  |  | 31 |  | 
|  | 15 |  |  |  |  | 80 |  | 
| 8 |  |  |  |  |  |  | extends 'App::GitGot::Command'; | 
| 9 | 15 |  |  | 15 |  | 4385 | use namespace::autoclean; | 
|  | 15 |  |  |  |  | 28 |  | 
|  | 15 |  |  |  |  | 73 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | sub options { | 
| 12 | 7 |  |  | 7 | 0 | 452 | my( $class , $app ) = @_; | 
| 13 |  |  |  |  |  |  | return ( | 
| 14 | 7 |  |  |  |  | 69 | [ 'add|a' => 'assign tags to the current repository' => { default => 0 } ] , | 
| 15 |  |  |  |  |  |  | [ 'all|A' => 'print out tags of all repositories' => { default => 0 } ] , | 
| 16 |  |  |  |  |  |  | [ 'remove|rm' => 'remove tags from the current repository' => { default => 0 } ] , | 
| 17 |  |  |  |  |  |  | ); | 
| 18 |  |  |  |  |  |  | } | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | sub _execute { | 
| 21 | 7 |  |  | 7 |  | 14 | my( $self, $opt, $args ) = @_; | 
| 22 |  |  |  |  |  |  |  | 
| 23 | 7 | 50 |  |  |  | 26 | return say "not in a got-monitored repo" unless $self->local_repo; | 
| 24 |  |  |  |  |  |  |  | 
| 25 | 6 | 100 | 100 |  |  | 229 | return say "can't --add and --remove at the same time" | 
| 26 |  |  |  |  |  |  | if $self->opt->add and $self->opt->remove; | 
| 27 |  |  |  |  |  |  |  | 
| 28 | 5 | 100 |  |  |  | 43 | if( $self->opt->add ) { | 
| 29 | 1 |  |  |  |  | 6 | return $self->_add_tags( @$args ); | 
| 30 |  |  |  |  |  |  | } | 
| 31 |  |  |  |  |  |  |  | 
| 32 | 4 | 100 |  |  |  | 16 | if( $self->opt->remove ) { | 
| 33 | 1 |  |  |  |  | 6 | return $self->_remove_tags( @$args ); | 
| 34 |  |  |  |  |  |  | } | 
| 35 |  |  |  |  |  |  |  | 
| 36 | 3 |  |  |  |  | 15 | $self->_print_tags; | 
| 37 |  |  |  |  |  |  | } | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | sub _add_tags { | 
| 40 | 1 |  |  | 1 |  | 3 | my( $self, @tags ) = @_; | 
| 41 |  |  |  |  |  |  |  | 
| 42 | 1 |  |  |  |  | 4 | $self->local_repo->add_tags( @tags ); | 
| 43 |  |  |  |  |  |  |  | 
| 44 | 1 |  |  |  |  | 56 | $self->write_config; | 
| 45 |  |  |  |  |  |  |  | 
| 46 | 1 |  |  |  |  | 1695 | say "tags added"; | 
| 47 |  |  |  |  |  |  | } | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | sub _print_tags { | 
| 50 | 3 |  |  | 3 |  | 5 | my $self = shift; | 
| 51 |  |  |  |  |  |  |  | 
| 52 | 3 |  |  |  |  | 21 | my %tags = map { $_ => 1 } split ' ', $self->local_repo->tags; | 
|  | 3 |  |  |  |  | 90 |  | 
| 53 |  |  |  |  |  |  |  | 
| 54 | 3 | 50 |  |  |  | 70 | if ( $self->opt->all ) { | 
| 55 | 0 |  | 0 |  |  | 0 | $tags{$_} ||= 0 for map { split ' ', $_->tags } $self->all_repos | 
|  | 0 |  |  |  |  | 0 |  | 
| 56 |  |  |  |  |  |  | } | 
| 57 |  |  |  |  |  |  |  | 
| 58 | 3 |  |  |  |  | 48 | for my $t ( sort keys %tags ) { | 
| 59 | 3 |  | 33 |  |  | 27 | say $t, ' *' x ( $self->opt->all and $tags{$t} ); | 
| 60 |  |  |  |  |  |  | } | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | } | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | sub _remove_tags { | 
| 65 | 1 |  |  | 1 |  | 4 | my( $self, @tags ) = @_; | 
| 66 |  |  |  |  |  |  |  | 
| 67 | 1 |  |  |  |  | 3 | $self->local_repo->remove_tags(@tags); | 
| 68 |  |  |  |  |  |  |  | 
| 69 | 1 |  |  |  |  | 29 | $self->write_config; | 
| 70 |  |  |  |  |  |  |  | 
| 71 | 1 |  |  |  |  | 1437 | say "tags removed"; | 
| 72 |  |  |  |  |  |  | } | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | 1; | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | __END__ |