Skip Menu |

This queue is for tickets about the MooseX-Getopt CPAN distribution.

Report information
The Basics
Id: 43255
Status: resolved
Priority: 0/
Queue: MooseX-Getopt

People
Owner: Nobody in particular
Requestors: drew [...] drewtaylor.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Patch to add support for --usage/--help/--?
I started using MooseX::Getopt yesterday and love it. However, I wanted to support "my_prog.pl --help" and print out all the nice documentation I added for each Getopt attribute. Here's a simple patch which supports it. No tests, but if you'll include this feature I'll write a test. :-)
Subject: MooseXGetopt_usage.patch
diff -u lib/perl/MooseX/Getopt.pm.orig lib/perl/MooseX/Getopt.pm --- lib/perl/MooseX/Getopt.pm.orig 2009-02-13 13:25:22.000000000 +0000 +++ lib/perl/MooseX/Getopt.pm 2009-02-13 14:56:13.000000000 +0000 @@ -51,6 +51,12 @@ my $params = $config_from_file ? { %$config_from_file, %{$processed{params}} } : $processed{params}; + # did the user request usage information? + if ( $processed{usage} && ($params->{'?'} or $params->{help} or $params->{usage}) ) + { + $processed{usage}->die(); + } + $class->new( ARGV => $processed{argv_copy}, extra_argv => $processed{argv}, @@ -416,6 +422,15 @@ If L<Getopt::Long/GetOptions> fails (due to invalid arguments), C<new_with_options> will throw an exception. +If L<Getopt::Long::Descriptive> is installed and any of the following +command line params are passed, the program will exit with usage +information. You can add descriptions for each option by including a +B<documentation> option for each attribute to document. + + --? + --help + --usage + If you have L<Getopt::Long::Descriptive> a the C<usage> param is also passed to C<new>. @@ -454,6 +469,8 @@ Ryan D Johnson, E<lt>ryan@innerfence.comE<gt> +Drew Taylor, E<lt>drew@drewtaylor.comE<gt> + =head1 COPYRIGHT AND LICENSE Copyright 2007-2008 by Infinity Interactive, Inc.
Applied as 47a89a8d, but if you could come up with some tests also, that'd be great!