Getopt::Lazy - Yet another lazy, minimal way of using Getopt::Long
use Getopt::Lazy 'help|h' => 'Show this help screen', 'verbose|v' => 'Show verbose output', 'output|o=s' => ["[FILE] Send the output to FILE", 'getopt.out'], 'output-encoding=s' => ['[ENCODING] Specify the output encoding', 'utf8'], -summary => 'a simple example usage of Getopt::Lazy', -usage => '%c %o file1 [file2 ..]', ; GetOptions; show_help and exit 1 unless @ARGV;
Got tired of the same tedious "getopt" things in every script you wrote? This module works for you!
Normally your script would go like this:
use File::Basename; use Getopt::Long; sub usage { my $msg = shift; my $cmd = basename $0; print $msg, "\n" if defined $msg; print <<__USAGE__; $cmd - Yet another tool for whatever you like Usage: $cmd [options...] file [more-file] Options: --boolean,-b Turn on the function A --string, -s STRING Specify the name of blahblah (defaults 'blahblah') --another-string, -as STRING Specify an alias for blahblah (defaults 'blahblah') ... __USAGE__ } my $boolean = 0; my $string = 'blahblah'; my $another_string = 'blahblah'; ... GetOptions( 'boolean|b' => \$boolean, 'string|s=s' => \$string, 'another-string|as=s' => \$string, ... ); usage and exit unless @ARGV;
The same thing using Getopt::Lazy:
use Getopt::Lazy 'boolean|b' => 'Turn on the function A', 'string|s=s' => ['[STRING] Specify the name of blahblah' => 'blahblah'], 'another-string|as=s' => ['[STRING] Specify an alias for blahblah' => 'blahblah'], -summary => 'Yet another tool for whatever you like', -usage => '%c %o file1 [more-file]', ; GetOptions; show_help and exit 1 unless @ARGV;
show_help() simply prints out this help screen:
$ lazy lazy - Yet another tool for whatever you like Usage: lazy [options..] file1 [more-file] Options: --another-string, -as STRING Specify an alias for blahblah (default: blahblah) --boolean Turn on the function A --string, -s STRING Specify the name of blahblah (default: blahblah)
Getopt::Lazy does two things for you: 1) spawning a variable for every given option, and 2) generating GNU-style help messages.
Show the help screen
Make Getopt::Long work!
Getopt::Lazy requires no configuration files or environment variables.
Getopt::Lazy depends on Getopt::Long.
None reported (so far so good.)
Please report any bugs or feature requests to bug-getopt-lazy@rt.cpan.org, or through the web interface at http://rt.cpan.org.
bug-getopt-lazy@rt.cpan.org
Ruey-Cheng Chen <rueycheng@gmail.com>
<rueycheng@gmail.com>
Copyright (c) 2007, 2015 Ruey-Cheng Chen <rueycheng@gmail.com>. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
To install Getopt::Lazy, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Getopt::Lazy
CPAN shell
perl -MCPAN -e shell install Getopt::Lazy
For more information on module installation, please visit the detailed CPAN module installation guide.