Options::Generator - Build options for the command line from a perl data structure
Version 0.01
use Options::Generator; my $og = Options::Generator->new; print $og->generate($data); or more detailed... my $og = Options::Generater->new({ outer_prefix => [ '-', '--' ], outer_assign => ' ', # default outer_separate => ' ', # default inner_assign => '=', # default inner_separate => ',', # default ... }); my $data = { foo => 'bar', o => undef, s => 'silly', options => [ 'one', 'two', { this => that }], blah => undef, }; prints: --foo bar --options one,two,this=that, --blah -o -s silly
Accepts a hashref of definitions
outer_prefix The prefix character to add to the outer options, defaults to a single hyphen if not specified. This is the only option that can accept an array reference for options that are single length. The first element will be assigned to single length options, the second element will be assigned to options greater that a single character. outer_prefx => '--' # --foo outer_prefix => '-' # -foo outer_prefix => [ '-', '--'] # -f --foo --bar -s -c
outer_assign The character to assign a value to the option, defaults to space if not specified. --foo bar outer_assign => '=' # --foo=bar
outer_separate The character to separate outer most options. Defaults to space if not specified. --foo bar outer_separate => ',' # --foo=bar,--boo=baz
inner_prefx The prefix character to add to the inner options (if applicable). No prefix by default --foo bar,baz,this=that inner_prefix => '+' # --foo +bar,+baz,+this=that
inner_assign The character to assign values to the inner options. Defaults to equals sign. --foo this=that,boo=baz
inner_separate The character to separate inner options. Defaults to comma
Examples of outputs with defaults
--foo --foo --bar --foo -b -z --bar --foo bar=baz,this=that -o -s --options -f blah
Returns a string of your options. Supply your perl data structure as a hash ref.
my $data = { foo => 'bar', bar => 'baz', inner => [ 'this', 'that', { one => 'two'} ], a => b c => undef, }; print $og->generate($hash);
Michael Kroher, <infrared at cpan.org>
<infrared at cpan.org>
Wrote this module for kvm-qemu generation stuff (hence the defaults).
Please report any bugs or feature requests to bug-commandline-generator at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Options-Generator. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-commandline-generator at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Options::Generator
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Options-Generator
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Options-Generator
CPAN Ratings
http://cpanratings.perl.org/d/Options-Generator
Search CPAN
http://search.cpan.org/dist/Options-Generator/
Copyright 2011 Michael Kroher.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install Options::Generator, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Options::Generator
CPAN shell
perl -MCPAN -e shell install Options::Generator
For more information on module installation, please visit the detailed CPAN module installation guide.