Crane::Options - Command line options and arguments parser
use Crane::Options; my $option = options->{'version'}; my $arg2 = args->[1];
Parses command line options and arguments. Options are available as hash reference returned by options function and arguments are available as array reference returned by args function.
You can configure options by passing list of array references when first call options function (see description below).
By default two options are available: version and help.
Not an option exaclty, just a separator in help output.
Equals to:
[]
Version information output.
[ 'version!', 'Shows version information and exits.' ]
Help output.
[ 'help!', Shows this help and exits.' ]
Returns hash reference to the command line options.
Can be configured when first called with the list of @options. To create an option you should pass a list of array references with one required and two mandatory items:
Scalar, required. Specification from Getopt::Long module.
Scalar. Text description (what is this option does?).
Hash reference. Additional parameters:
Default value for option if option does not exist.
Flag that option should be exists.
Separator is empty array reference.
Returns array reference to command line arguments.
Parses command line arguments list @ARGV and return reference to hash.
See @options parameter description.
Where %s is specification string.
Fires when required parameter of specification is not defined or incorrect.
Where %s is an option name.
Option does not exist but required.
Configuration:
options( [ 'config|C=s', 'Path to configuration file.' ], $OPT_SEPARATOR, $OPT_VERSION, $OPT_HELP, );
Help output:
example.pl <options> <args> -C --config Path to configuration file. --version Shows version information and exists. -? --help Shows this help and exits.
options( [ 'daemon|M!', 'Run as daemon.', { 'default' => 1 } ], $OPT_SEPARATOR, [ 'from=s', 'Start of the interval.', { 'required' => 1 } ], [ 'to=s', 'End of the interval.', { 'required' => 1 } ], $OPT_SEPARATOR, $OPT_VERSION, $OPT_HELP, );
example.pl <options> <args> -M --daemon Run as daemon. --from Start of the interval. --to End of the interval. --version Shows version information and exists. -? --help Shows this help and exits.
Please report any bugs or feature requests to https://rt.cpan.org/Public/Bug/Report.html?Queue=Crane or to https://github.com/temoon/crane/issues.
Tema Novikov, <novikov.tema@gmail.com>
Copyright (C) 2013-2014 Tema Novikov.
This library is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0. For details, see the full text of the license in the file LICENSE.
RT Cpan
https://rt.cpan.org/Public/Dist/Display.html?Name=Crane
Github
https://github.com/temoon/crane
To install Crane, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Crane
CPAN shell
perl -MCPAN -e shell install Crane
For more information on module installation, please visit the detailed CPAN module installation guide.