Created
May 16, 2009 00:14
-
-
Save hercynium/112510 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my $opt_parser = OptParser->new(); | |
$opt_parser->add_option( | |
name => "foo" # name used to refer to this option | |
short => "f" # use as -f | |
long => "foo" # use as --foo | |
depends => "bar|baz" # option only valid if bar or baz is specified. using | |
# an array to list depends may be simpler... or not | |
conflicts => "buh" # option conflicts with option buh. | |
required => "yes" # option is required (if depends are specified, only | |
# check after depends passes) | |
type => "string" # data type (string|flag) | |
default => "wibble" # default value if none specified | |
help => "..." # text to show when -h is used to display help | |
error => "..." # text to show if option does not validate | |
multi => "no" # allow option to be specified multiple times | |
# (no|yes|group) | |
group => "fuh" # When showing help, group this option with others | |
# who are assigned to group fuh | |
validate => \&sub # ref to a sub that can validate the option | |
after => [qw(baz)] # only validate *after* baz | |
); | |
# Sometimes in the help, usage and docs you want certain options to be | |
# grouped together. You may also want to apply validation to all the | |
# options in a group together. | |
$opt_parser->add_group( | |
name => "fuh" # name of the option group | |
validate => \&sub # ref to a sub that can validate all the | |
# options in the group | |
help => "..." # text describing the group when displaying help | |
members => [qw(foo baz)] # options belonging to this group. | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment