1package App::GitGot::Command::do;
2our $AUTHORITY = 'cpan:GENEHACK';
3$App::GitGot::Command::do::VERSION = '1.339';
4# ABSTRACT: run command in many repositories
5use 5.014;
6
7use Capture::Tiny qw/ capture_stdout /;
8use File::chdir;
9use Types::Standard -types;
10
11use App::GitGot -command;
12
13use Moo;
14extends 'App::GitGot::Command';
15use namespace::autoclean;
16
17sub options {
18  my( $class , $app ) = @_;
19  return (
20    [ '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
25sub _execute {
26  my $self = shift;
27
28  for my $repo ( $self->active_repos ) {
29    $self->_run_in_repo( $repo => $self->opt->command );
30  }
31}
32
33sub _run_in_repo {
34  my( $self, $repo, $cmd ) = @_;
35
36  if ( not -d $repo->path ) {
37    printf "repo %s: no repository found at path '%s'\n",
38      $repo->label, $repo->path;
39    return;
40  }
41
42  say "\n## repo ", $repo->label, "\n" unless $self->opt->with_repo;
43
44  my $prefix = $self->opt->with_repo ? $repo->label . ': ' : '';
45
46  say $prefix, $_ for split "\n", capture_stdout {
47    $CWD = $repo->path;
48    system $cmd;
49  };
50}
51
521;
53
54### FIXME docs
55
56__END__
57
58=pod
59
60=encoding UTF-8
61
62=head1 NAME
63
64App::GitGot::Command::do - run command in many repositories
65
66=head1 VERSION
67
68version 1.339
69
70=head1 AUTHOR
71
72John SJ Anderson <john@genehack.org>
73
74=head1 COPYRIGHT AND LICENSE
75
76This software is copyright (c) 2020 by John SJ Anderson.
77
78This is free software; you can redistribute it and/or modify it under
79the same terms as the Perl 5 programming language system itself.
80
81=cut
82