Beagle

 view release on metacpan or  search on metacpan

lib/Beagle/Cmd.pm  view on Meta::CPAN

package Beagle::Cmd;
use Any::Moose;
use Beagle::Util;
extends any_moose('X::App::Cmd');

before 'run' => sub {
    @ARGV = map { defined $_ ? decode( locale => $_ ) : $_ } @ARGV;

    if ( !@ARGV ) {
        my $command =
          $ENV{BEAGLE_DEFAULT_COMMAND}
          ? decode( locale => $ENV{BEAGLE_DEFAULT_COMMAND} )
          : core_config->{default_command};

        if ($command) {
            require Text::ParseWords;
            @ARGV = Text::ParseWords::shellwords($command);
        }
        else {
            @ARGV = 'shell';
        }
    }

    my $cmd = $ARGV[0];

    # default cmd is today
    $cmd = 'today' unless defined $cmd;

    if ( $cmd =~ /--?v(?:ersion)?/ ) {
        $ARGV[0] = 'version';
    }
    elsif ( $cmd eq 'help' || $cmd =~ /^--?h(?:help)?/ ) {
        if ( grep { /^[^-]/ } @ARGV[1..$#ARGV] ) {
            $ARGV[0] = 'help';
        }
        else {
            $ARGV[0] = 'commands';
        }
    }
    elsif ( $cmd eq '.' || $cmd =~ /^-/ ) {
        unshift @ARGV, core_config->{default_command};
    }


    if ( alias()->{$cmd} ) {
        require Text::ParseWords;
        my @words = Text::ParseWords::shellwords( alias()->{$cmd} );

        shift @ARGV;

        unshift @ARGV, @words;
    }

};

sub execute_command {
    my ( $self, $cmd, $opt, @args ) = @_;
    $cmd->validate_args( $opt, \@args );

    for my $key ( keys %$opt ) {
        if ( $key =~ /-/ ) {
            my $new = $key;
            $new =~ s!-!_!g;
            $opt->{$new} = delete $opt->{$key};
        }
    }

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 5.306 seconds using v1.00-cache-2.02-grep-82fe00e-cpan-9f2165ba459b )