Skip Menu |

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

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

People
Owner: bobtfish [...] bobtfish.net
Requestors: ether [...] cpan.org
Cc:
AdminCc:

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



Subject: Usage description is not being handled as per the documentation
It would appear that passing the options --?, --help or --usage are not treated specially by the code.. e.g. the output is the same if any of these options are passed, vs. some other random option that does not exist. Perhaps I am misreading the documentation, but the suggestion is that something special would happen, or at least the string "Unknown option: help" (or usage, or ?) would not be printed ahead of the attribute descriptions. Now, I know this can be achieved by adding an explicit 'help' attribute, e.g.: has [ qw(help usage) ] => ( is => 'ro', isa => 'Bool', documentation => 'placeholder help documentation', ); sub _getopt_full_usage { my ($self, $usage) = @_; print "arbitrary usage text here\n"; print $usage->text; exit 0; } ...but this won't work for passing --?, as '?' is not a legal Moose attribute name. I found these lines in MooseX::Getopt::Basic, but they don't seem to be triggered (the code never gets this far - execution is aborted in _parse_argv()): # did the user request usage information? if ( $processed{usage} && ($params->{'?'} or $params->{help} or $params->{usage}) ) { $class->_getopt_full_usage($processed{usage}); }
From: bitcard [...] froods.org
On Thu May 20 21:11:00 2010, bitcard@froods.org wrote: Show quoted text
> It would appear that passing the options --?, --help or --usage are not > treated specially by the code.. e.g. the output is the same if any of > these options are passed, vs. some other random option that does not
exist. FWIW, I got things to work with this code (I noticed there were a few related tickets in the queue, so I would suggesting updating the documentation): package MyApp::Foo; use strict; use warnings; use Moose; use MooseX::ClassAttribute; with 'MooseX::Getopt::Strict' => { excludes => [qw(_getopt_full_usage)] }; has [qw(help usage)] => ( is => 'ro', isa => 'Bool', documentation => 'Prints this usage documentation.', traits => ['Getopt'], ); class_has instructions => ( is => 'ro', isa => 'Str', init_arg => undef, # don't allow in constructor default => 'Instruction text -- override in your derived class' ); # called when --help or --usage is used on command line sub _getopt_full_usage { my ($this, $usage) = @_; print $this->instructions, "\n"; print $usage->text, "\n"; exit; } no Moose; __PACKAGE__->meta->make_immutable; 1; I'm going to open another ticket now with a feature suggestion to pass the usage object back to the class, so it can error out on its own (e.g. if some arguments fail to validate) with the same usage text.
From: bitcard [...] froods.org
Fixed in branch topic/save_usage_obj.
Merged to master, thanks very much for the patch!