App-GitGot

 view release on metacpan or  search on metacpan

lib/App/GitGot/Command.pm  view on Meta::CPAN

package App::GitGot::Command;
our $AUTHORITY = 'cpan:GENEHACK';
$App::GitGot::Command::VERSION = '1.339';
# ABSTRACT: Base class for App::GitGot commands
use 5.014;

use App::Cmd::Setup -command;
use Cwd;
use File::HomeDir::Tiny ();
use List::Util              qw/ max first /;
use Path::Tiny;
use Try::Tiny;
use Types::Standard -types;
use YAML                    qw/ DumpFile LoadFile /;

use App::GitGot::Repo::Git;
use App::GitGot::Repositories;
use App::GitGot::Types -all;

use Moo;
use MooX::HandlesVia;
use namespace::autoclean;

sub opt_spec {
  my( $class , $app ) = @_;

  return (
    [ 'all|a'            => 'use all available repositories' ] ,
    [ 'by_path|p'        => 'if set, output will be sorted by repo path (default: sort by repo name)' ] ,
    [ 'color_scheme|c=s' => 'name of color scheme to use' => { default => 'dark' } ] ,
    [ 'configfile|f=s'   => 'path to config file' => { default => path( File::HomeDir::Tiny::home() , '.gitgot') , required => 1 } ] ,
    [ 'no_color|C'       => 'do not use colored output' => { default => 0 } ] ,
    [ 'quiet|q'          => 'keep it down' ] ,
    [ 'skip_tags|T=s@'   => 'select repositories not tagged with these words' ] ,
    [ 'tags|t=s@'        => 'select repositories tagged with these words' ] ,
    [ 'verbose|v'        => 'bring th\' noise'] ,
    $class->options($app)
  );
}

sub options {}

has active_repo_list => (
  is          => 'lazy',
  isa         => ArrayRef[GotRepo] ,
  handles_via => 'Array' ,
  handles     => {
    active_repos => 'elements' ,
  } ,
);

sub _build_active_repo_list {
  my ( $self ) = @_;

  return $self->full_repo_list
    if $self->all or ! $self->tags and ! $self->skip_tags and ! @{ $self->args };

  my $list = _expand_arg_list( $self->args );

  my @repos;
 REPO: foreach my $repo ( $self->all_repos ) {
    if ( grep { $_ eq $repo->number or $_ eq $repo->name } @$list ) {
      push @repos, $repo;
      next REPO;
    }

    if ( $self->skip_tags ) {
      foreach my $tag ( @{ $self->skip_tags } ) {
        next REPO if grep { $repo->tags =~ /\b$_\b/ } $tag;
      }
    }

    if ( $self->tags ) {
      foreach my $tag ( @{ $self->tags } ) {
        if ( grep { $repo->tags =~ /\b$_\b/ } $tag ) {
          push @repos, $repo;
          next REPO;
        }
      }
    }
    push @repos, $repo unless $self->tags or @$list;
  }



( run in 0.630 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )