Skip Menu |

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

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

People
Owner: Nobody in particular
Requestors: ether [...] cpan.org
Cc:
AdminCc:

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



Subject: Feature suggestion: pass the Usage object back to the class.
Inside _parse_argv, there is a Getopt::Long::Descriptive::Usage that gets generated which is used as an argument for _getopt_full_usage() when printing the usage information (when --help or --usage is supplied, or there is an error parsing the arguments). It would be really handy if this object were saved and sent back to the class so it can use it in the case of future errors, e.g. if argument validation fails. I would suggest adding another attribute in the composing class: # in Basic.pm: has _usage => ( is => 'rw', isa => 'Getopt::Long::Descriptive::Usage', metaclass => 'NoGetopt', ); sub new_with_options { ... $class->new( _usage => $processed{usage}, # ... other args (ARGV, extra_argv etc) ); } So in the composing class, one could do: sub do_work { my $this = shift; if (not validate($this->foo)) { # exit with usage info print "Your foo argument does not validate\n"; print $this->usage->text, "\n"; exit; } } "usage" might be a better attribute name than _usage (as ARGV and extra_argv don't use underscores), but it conflicts with the usage attr I add in the solution I provided to https://rt.cpan.org/Public/Bug/Display.html?id=57683: has [qw(help usage)] => ( is => 'ro', isa => 'Bool', documentation => 'Prints this usage documentation.', traits => ['Getopt'], ); Although I suppose that could be rewritten thusly: has "_$_" => ( is => 'ro', isa => 'Bool', documentation => 'Prints this usage documentation.', traits => ['Getopt'], cmd_flag => $_, ) for (qw(help usage)); If I receive general noises of approval for this suggestion, I might put submit a patch. Please make appropriate noise.
From: bitcard [...] froods.org
On Wed Jun 23 14:03:31 2010, bitcard@froods.org wrote: Show quoted text
> If I receive general noises of approval for this suggestion, I might put > submit a patch. Please make appropriate noise.
I made noises to myself and produced this patch -- please review branch topic/save_usage_obj. (This branch also contains related fixes to the handling of the --help, --usage, --? options.)
Thanks for the patches!