Getopt::Long::Descriptive - Getopt::Long with usage text
0.06
Convenient wrapper for Getopt::Long and program usage output
use Getopt::Long::Descriptive; my ($opts, $usage) = describe_options($format, @opts, \%arg);
$format = "usage: myprog %o myarg...";
%o will be replaced with a list of the short options, as well as the text "[long options...]" if any have been defined.
%o
%c will be replaced with what Getopt::Long::Descriptive thinks is the program name (see "prog_name"). You can override this guess by calling prog_name($string) yourself.
%c
prog_name($string)
Because of this, any literal % symbols will need to be written as %%.
%
%%
Option specifications are the same as in Getopt::Long. You should pass in an array of arrayrefs whose first elements are option specs and whose second elements are descriptions.
my @opts = ( [ "verbose|V" => "be noisy" ], [ "logfile=s" => "file to log to" ], );
Option specifications may have a third hashref argument. If present, this configures extra restrictions on the value or presence of that option.
You may cause a blank line to be printed by passing an empty arrayref. Likewise, a plain descriptive line will be printed if you pass an arrayref with a single element:
@opts = ( $option, [], [ 'other options:' ], $other_option, );
implies => 'bar' implies => [qw(foo bar)] implies => { foo => 1, bar => 2 }
required => 1
hidden => 1
This option will not show up in the usage text.
You can achieve this same behavior by using the string hidden for the option's description.
hidden
one_of => \@option_specs
Useful for a group of options that are related. Each option spec is added to the list for normal parsing and validation.
Your option name will end up with a value of the name of the option that was chosen. For example, given the following spec:
[ "mode" => hidden => { one_of => [ [ "get|g" => "get the value" ], [ "set|s" => "set the value" ], [ "delete" => "delete it" ], ] } ],
No usage text for 'mode' will be displayed, though get/set/delete will all have descriptions.
If more than one of get/set/delete (or their short versions) are given, an error will be thrown.
If @ARGV is --get, a dump of the resultant option hashref would look like this:
@ARGV
--get
{ get => 1, mode => 'get' }
NOTE: get would not be set if mode defaulted to 'get' and no arguments were passed in.
get
mode
WARNING: Even though the option sub-specs for one_of are meant to be 'first class' specs, some options don't make sense with them, e.g. required.
one_of
required
As a further shorthand, you may specify one_of options using this form:
[ mode => \@option_specs, \%constraints ]
In addition, any constraint understood by Params::Validate may be used.
(Internally, all constraints are translated into Params::Validate options or callbacks.)
If the last parameter is a hashref, it contains extra arguments to modify the way describe_options works. Valid arguments are:
describe_options
getopt_conf - an arrayref of strings, passed to Getopt::Long::Configure
See SYNOPSIS; returns a hashref of option values and an object that represents the usage statement.
The usage statement has several methods:
$usage->text returns the usage string
$usage->text
$usage->warn prints usage to STDERR
$usage->warn
$usage->die dies with the usage string
$usage->die
prog_name
A helper function that returns the basename of $0, grabbed at compile-time.
$0
:types
Any of the Params::Validate type constants (SCALAR, etc.) can be imported as well. You can get all of them at once by importing :types.
SCALAR
:all
This gets you everything.
$MungeOptions
When $Getopt::Long::Descriptive::MungeOptions is true, some munging is done to make option names more hash-key friendly:
$Getopt::Long::Descriptive::MungeOptions
All keys are lowercased
- is changed to _
-
_
The default is a true value.
Getopt::Long Params::Validate
Hans Dieter Pearcey, <hdp@cpan.org>
<hdp@cpan.org>
Please report any bugs or feature requests to bug-getopt-long-descriptive@rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Getopt-Long-Descriptive. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-getopt-long-descriptive@rt.cpan.org
Copyright 2005 Hans Dieter Pearcey, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Getopt::Long::Descriptive, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Getopt::Long::Descriptive
CPAN shell
perl -MCPAN -e shell install Getopt::Long::Descriptive
For more information on module installation, please visit the detailed CPAN module installation guide.