CLI-Helpers
view release on metacpan or search on metacpan
lib/CLI/Helpers.pm view on Meta::CPAN
package CLI::Helpers;
# ABSTRACT: Subroutines for making simple command line scripts
# RECOMMEND PREREQ: App::Nopaste
# RECOMMEND PREREQ: Term::ReadLine::Gnu
use strict;
use feature qw(state);
use warnings;
use Capture::Tiny qw(capture);
use File::Basename;
use Getopt::Long qw(GetOptionsFromArray);
use IO::Interactive qw( is_interactive );
use JSON::MaybeXS;
use Module::Load qw(load);
use Ref::Util qw(is_ref is_arrayref is_hashref);
use Sys::Syslog qw(:standard);
use Term::ANSIColor 2.01 qw(color colored colorstrip);
use Term::ReadKey;
use Term::ReadLine;
use YAML::XS ();
our $VERSION = '2.2'; # VERSION
# Capture ARGV at Load
my @ORIG_ARGS;
BEGIN {
@ORIG_ARGS = @ARGV;
}
require Exporter;
our @ISA = qw(Exporter);
my @export_output = qw(output verbose debug debug_var);
my @export_input = qw(prompt menu text_input confirm pwprompt);
my @export_always = qw(cli_helpers_initialize options_description);
our @EXPORT_OK = ( @export_output, @export_input, @export_always );
our %EXPORT_TAGS = (
all => [@export_always, @export_input, @export_output],
input => [@export_always, @export_input],
output => [@export_always, @export_output],
);
my $ARGV_AT_INIT = 0;
my $COPY_ARGV = 0;
our $_init_complete = 0;
sub import {
my (@args) = @_;
my @import = ();
# We need to process the config options
my $explicit_argv = 0;
foreach my $arg ( @args ) {
if( $arg eq 'delay_argv' ) {
$ARGV_AT_INIT = 0;
$explicit_argv++;
}
elsif( $arg eq 'preprocess_argv' ) {
$ARGV_AT_INIT = 1;
$explicit_argv++;
}
elsif( $arg eq 'copy_argv' ) {
$COPY_ARGV = 1;
}
# Not a config option, pass through
else {
push @import, $arg;
}
}
if ( $explicit_argv != 1 ) {
my ($package) = caller;
$ARGV_AT_INIT = $package eq 'main';
}
( run in 1.641 second using v1.01-cache-2.11-cpan-39bf76dae61 )