Getopt-Alt
view release on metacpan or search on metacpan
lib/Getopt/Alt.pm view on Meta::CPAN
helper => 1, # default when using get_options
sub_command => 1, # stop processing at first non argument parameter
},
[
'string|s=s',
'int|i=i',
'hash|h=s%',
'array|a=s@',
'increment|c+',
'nullable|n=s?',
'negatable|b!',
'fixed_values|fixed-values|f=[a|bunch|of|fixed|values]',
],
);
print $cmd; # sub command
# with sub command details
my $options = get_options(
{
helper => 1, # default when using get_options
sub_command => {
sub => [ 'suboption' ],
other => [ 'verbose|v' ],
},
},
[
'string|s=s',
'int|i=i',
'hash|h=s%',
'array|a=s@',
'increment|c+',
'nullable|n=s?',
'negatable|b!',
'fixed_values|fixed-values|f=[a|bunch|of|fixed|values]',
],
);
print Dumper $option->opt; # command with sub command options merged in
# auto_complete
my $options = get_options(
{
helper => 1, # default when using get_options
auto_complete => sub {
my ($opt, $auto) = @_;
# ... code for auto completeion
# called if --auto-complete specified on the command line
},
},
[
'string|s=s',
'int|i=i',
],
);
=head1 DESCRIPTION
The aim of C<Getopt::Alt> is to provide an alternative to L<Getopt::Long> that
allows a simple command line program to easily grow in complexity. L<Getopt::Lon>
can be expanded from a simple command line option passer to allow sub-commands.
Option processing may stop at the sub-command or with the help of modules can
cascade the processing into the sub command's module or config.
The simple usage is quite similar to L<Getopt::Long>:
In C<Getopt::Long> you might get your options like:
use Getopt::Long;
my %options = ( string => 'default' );
GetOptions(
\%options,
'string|s=s',
...
);
The found options are now stored in the C<%options> hash.
In C<Getopt::Alt> you might do the following:
use Getopt::Alt qw/get_options/;
my %default = ( string => 'default' );
my $opt = get_options(
\%default,
'string|s=s',
...
);
my %options = %{ $opt->opt };
This will also result in the options stored in the C<%options> hash.
Some other differences between Getopt::Alt and Getopt::Long include:
=over 4
=item *
Bundling - is on by default
=item *
Case sensitivity is on by default
=item *
Throws error rather than returning errors.
=item *
Can work with sub commands
=back
=head1 SUBROUTINES/METHODS
=head2 Exported
=head3 C<get_options (@options | $setup, $options)>
=head3 C<get_options ($default, 'opt1', 'opt2' ... )>
This is the equivalent of calling new(...)->process but it does some extra
argument processing.
( run in 2.700 seconds using v1.01-cache-2.11-cpan-df04353d9ac )