File Coverage

blib/lib/App/GitGot/Command/do.pm
Criterion Covered Total %
statement 32 34 94.1
branch 5 6 83.3
condition n/a
subroutine 11 11 100.0
pod 0 1 0.0
total 48 52 92.3


line stmt bran cond sub pod time code
1             package App::GitGot::Command::do;
2             our $AUTHORITY = 'cpan:GENEHACK';
3             $App::GitGot::Command::do::VERSION = '1.339';
4             # ABSTRACT: run command in many repositories
5 15     15   10433 use 5.014;
  15         66  
6              
7 15     15   8334 use Capture::Tiny qw/ capture_stdout /;
  15         99891  
  15         1142  
8 15     15   135 use File::chdir;
  15         41  
  15         1941  
9 15     15   122 use Types::Standard -types;
  15         42  
  15         156  
10              
11 15     15   69446 use App::GitGot -command;
  15         48  
  15         146  
12              
13 15     15   6614 use Moo;
  15         46  
  15         138  
14             extends 'App::GitGot::Command';
15 15     15   6470 use namespace::autoclean;
  15         46  
  15         143  
16              
17             sub options {
18 2     2 0 270 my( $class , $app ) = @_;
19             return (
20 2         42 [ 'command|e=s' => 'command to execute in the different repos' => { required => 1 } ] ,
21             [ 'with_repo' => 'prepend all output lines with the repo name' => { default => 0 } ] ,
22             );
23             }
24              
25             sub _execute {
26 2     2   13 my $self = shift;
27              
28 2         72 for my $repo ( $self->active_repos ) {
29 4         3116 $self->_run_in_repo( $repo => $self->opt->command );
30             }
31             }
32              
33             sub _run_in_repo {
34 4     4   46 my( $self, $repo, $cmd ) = @_;
35              
36 4 50       104 if ( not -d $repo->path ) {
37 0         0 printf "repo %s: no repository found at path '%s'\n",
38             $repo->label, $repo->path;
39 0         0 return;
40             }
41              
42 4 100       42 say "\n## repo ", $repo->label, "\n" unless $self->opt->with_repo;
43              
44 4 100       149 my $prefix = $self->opt->with_repo ? $repo->label . ': ' : '';
45              
46 4         423 say $prefix, $_ for split "\n", capture_stdout {
47 4     4   4219 $CWD = $repo->path;
48 4         20941 system $cmd;
49             };
50             }
51              
52             1;
53              
54             ### FIXME docs
55              
56             __END__