On Sat, Feb 13, 2010 at 20:04, Tomas Doran <[email protected]> wrote:
>
> On 12 Feb 2010, at 21:44, Ævar Arnfjörð Bjarmason wrote:
>
>> I got my Moose commit bit today. I added some docs on how to use
>> MooseX::Getopt. I'd like to add more but first I have to ask if the
>> things I want to document are sane, and there are some things I don't
>> know how to do yet.
>>
>> Here are some things I've wanted to do which I haven't found in the
>> documentation:
>>
>> * Add modify the default --help output
>>
>> I overrode _getopt_full_usage in my application to do this, see the
>> code here:
>> http://github.com/hinrik/hailo/blob/master/lib/Hailo.pm#L209
>
> That's what I added that hook for..
>
>> However I can't get this to work in the case where I supply an invalid
>> option, e.g. --this-does-not-exist, then I just get the default
>> output. There's a bug for this for my application here:
>> http://github.com/hinrik/hailo/issues#issue/12
>
> Override _getopt_spec_exception and make it call getopt_full_usage.
>
> In the case of Catalyst, unknown options in the scripts used to warn, so in
> Catalyst::ScriptRole I just define the method as empty.
>
>> * Make 'foo' equivalent to 'foo --help'
>>
>> I did this simply by doing:
>>
>>   @ARGV = qw(--help) unless @ARGV;
>>   Hailo->new_with_options->run;
>>
>> It works, but is this a sane way to do it? I.e. something we want to
>> document for users?
>
> Hmm.. I think a role which made options processing (i.e. new with options)
> work like this would be probably be a better idea than documenting messing
> with @ARGV directly.
>
>>
>> * has help => ( ... )
>>
>> How does this work? Putting it in my program magically gives me --help
>> but greping the source I can't find out why. Commit
>> 47a89a8dec3d21759af9d3e9fbf06149a2870543 added support for --?,
>> --usage and --help but setting a help attribute only gives me the
>> latter.
>
> You need to add cmd_aliases to the other flags that you want that to work
> for. Again see Catalyst::ScriptRole.
>
> And see the line below '# did the user request usage information' in
> MooseX::Getopt::Basic - yes, how it works is a bit tricky, basically due to
> how Getopt and GLD themselves work :/
>
> Feel free to catch me in #moose for a further natter about this :)

Thanks. That's all very useful. I'd been looking for some code that
used MX::GO but I didn't find that Catalyst script.

I'll come up with some examples and add test / docs to MX::GO when I have time.

Reply via email to