Getopt::CommandLineExports

Allow suroutines within a script to export comand line options with bash auto completion
Download

Getopt::CommandLineExports Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Robert Haxton
  • Publisher web site:
  • http://search.cpan.org/~rhaxton/

Getopt::CommandLineExports Tags


Getopt::CommandLineExports Description

Getopt::CommandLineExports is a Perl module intended to provide the capability to have a single script export many subcommands in a consistant manner.In the example above, the script is named "TestCommandLineExports". On a bash style command line, the following commands would work: TestCommandLineExports twoScalars --ONE "Arg1" --TWO "Arg2"and would print: Arg1, Arg2while TestCommandLineExports twoScalars --TWO "Arg2"would print: twoScalars missing required argument: --ONETestCommandLineExports twoScalars may also be called through a CGI interface as well.The principle use of this was to provide an easy, consistant, method to provide unit test ability for scripts. It also allows for a single script to export multiple subcommands and, with the included bash auto completion function, allows for the subcommands and options to integrate nicely with the bash shell.SYNOPSISExample Code: use strict; use warnings; use Getopt::CommandLineExports qw(®AC &parseArgsByPosition &parseArgs &checkArgs $scriptName @exportedSubs %cmdLines); $scriptName = qq; %cmdLines = ( twoScalars => , oneHash => , oneList => , ); sub twoScalars { my %h = ( ONE => undef, TWO => undef, ( parseArgs \@_, @{$cmdLines{twoScalars}}), ); print "twoScalars missing required argument:\n" . join( "\n", checkArgs \%h ) . "\n" if ( checkArgs \%h ); return " $h{ONE} , $h{TWO} \n"; } sub oneHash { my %h = ( ONE => undef, ( parseArgs \@_, @{$cmdLines{oneHash}}), ); print "oneHash missing required argument:\n" . join( "\n", checkArgs \%h ) . "\n" if ( checkArgs \%h ); print "oneHash\n"; print join("\n", (%{$h{ONE}})); } sub oneList { my %h = ( ONE => undef, ( parseArgs \@_, @{$cmdLines{oneList}}), ); print "oneList missing required argument:\n" . join( "\n", checkArgs \%h ) . "\n" if ( checkArgs \%h ); print "oneList\n"; print join("\n",@{$h{ONE}}); } # The "Main" subroutine. Not included in package, must be added manually to a script if ( defined $ARGV ) { if ( defined( &{ $ARGV } ) ) { no strict 'refs'; my $subRef = shift @ARGV; print join( "\n", &$subRef(@ARGV) ) . "\n" unless $subRef =~ /regAC/ ; &$subRef($scriptName, \@exportedSubs, \%cmdLines) if $subRef =~ /regAC/ ; exit 0; } } # some unit test examples: twoScalars "Hello1", "Hello2"; twoScalars {ONE => "Hello1", TWO => "Hello2"}; twoScalars "--ONE Hello1 --TWO Hello2"; twoScalars "--ONE", "Hello1", "--TWO", "Hello2"; twoScalars "--ONE", "Hello1", "--TWO", "Hello2", "--THREE", "Hello3"; # complains about "unknown option: three"Product's homepage


Getopt::CommandLineExports Related Software