App-GitGot
view release on metacpan or search on metacpan
lib/App/GitGot/Command/add.pm view on Meta::CPAN
package App::GitGot::Command::add;
our $AUTHORITY = 'cpan:GENEHACK';
$App::GitGot::Command::add::VERSION = '1.339';
# ABSTRACT: add a new repo to your config
use 5.014;
use Class::Load qw/ try_load_class /;
use Config::INI::Reader;
use Cwd;
use IO::Prompt::Simple;
use List::Util qw/ any pairmap /;
use Path::Tiny;
use PerlX::Maybe;
use Types::Standard -types;
use App::GitGot -command;
use App::GitGot::Repo::Git;
use Moo;
extends 'App::GitGot::Command';
use namespace::autoclean;
sub options {
my( $class , $app ) = @_;
return (
[ 'defaults|D' => 'FIXME' => { default => 0 } ] ,
[ 'origin|o=s' => 'FIXME' => { default => 'origin' } ] ,
[ 'recursive' => 'search all sub-directories for repositories' => { default => 0 } ],
);
}
sub _use_io_page { 0 }
sub _execute {
my ( $self, $opt, $args ) = @_;
my @dirs = @$args;
push @dirs, '.' unless @dirs; # default dir is this one
if( $self->opt->recursive ) { # hunt for repos
try_load_class( 'Path::Iterator::Rule' )
or die "--recursive requires module 'Path::Iterator::Rule' to be installed\n";
Path::Iterator::Rule->add_helper(
is_git => sub {
return sub {
my $item = shift;
return -d "$item/.git";
}
}
);
@dirs = Path::Iterator::Rule->new->dir->is_git->all(@dirs);
}
$self->_process_dir($_) for map { path($_)->absolute } @dirs;
}
sub _build_new_entry_from_user_input {
my( $self, $path ) = @_;
unless ( -e "$path/.git" ) {
say STDERR "ERROR: Non-git repos not supported at this time.";
exit(1);
}
my( $repo, $type ) = $self->_init_for_git( $path );
# if 'defaults' option is true, tell IO::Prompt::Simple to use default choices
$ENV{PERL_IOPS_USE_DEFAULT} = $self->opt->defaults;
return unless prompt( "\nAdd repository at '$path'? ", { yn => 1, default => 'y' } );
my $name = prompt( 'Name? ', lc path( $path )->basename );
my $remote;
if ( 1 == scalar keys %$repo ) { # one remote? No choice
($remote) = values %$repo;
}
else {
$remote = prompt( 'Tracking remote? ', {
( run in 0.660 second using v1.01-cache-2.11-cpan-98e64b0badf )