CASCM-CLI
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/CASCM/CLI.pm view on Meta::CPAN
package CASCM::CLI;
#######################
# LOAD MODULES
#######################
use 5.008001;
use strict;
use warnings FATAL => 'all';
use Carp qw(croak carp);
use File::Spec;
use Config::Tiny;
use File::HomeDir;
use CASCM::Wrapper;
use Log::Any::Adapter;
use Hash::Merge qw(merge);
use Getopt::Mini ( later => 1 );
use Log::Any::Adapter::Callback;
use Getopt::Long qw(GetOptionsFromArray);
use Object::Tiny qw(cascm exitval context);
#######################
# VERSION
#######################
our $VERSION = '0.1.1';
#######################
# RUNNER
#######################
sub run {
my ( $self, @args ) = @_;
# Initialize
$self->_init();
local @ARGV = ();
# Parse main arguments
my $main_options = {};
GetOptionsFromArray( \@args, $main_options, $self->_main_opt_spec() )
or $self->_print_bad_opts();
# Get Subcommand
my $subcmd = shift @args;
if ( $subcmd and ( $subcmd !~ m{^[a-z]+$}xi ) ) {
$self->_print_bad_subcmd($subcmd);
}
# Get Subcommand options
my %sub_options = getopt(
hungry_flags => 1,
argv => [@args],
);
delete $sub_options{_argv} if exists $sub_options{_argv};
# Get Subcommand arguments
my @sub_args;
if ( exists $sub_options{''} ) {
if ( ref( $sub_options{''} ) eq 'ARRAY' ) {
push( @sub_args, @{ $sub_options{''} } );
}
else {
push( @sub_args, $sub_options{''} );
}
delete $sub_options{''};
} ## end if ( exists $sub_options...)
# Make lowercase
$subcmd = '' if not defined $subcmd;
$subcmd = lc($subcmd);
# Check for help
if ( ( $subcmd eq 'help' ) or ( $main_options->{help} ) ) {
$self->_print_help();
exit 0;
} ## end if ( ( $subcmd eq 'help'...))
# Check for version
if ( ( $subcmd eq 'version' ) or ( $main_options->{version} ) ) {
$self->_print_version();
exit 0;
} ## end if ( ( $subcmd eq 'version'...))
# Check for Subcommand
if ( not $subcmd ) {
$self->_print_help();
exit 1;
} ## end if ( not $subcmd )
# Initialize Logger
$self->_init_logger();
# Initialize context
$self->_init_context( $main_options->{context} || '' );
# Initialize CASCM
view all matches for this distributionview release on metacpan - search on metacpan
( run in 4.515 seconds using v1.00-cache-2.02-grep-82fe00e-cpan-72ae3ad1e6da )