Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

How can I configure the perl App::Cmd module to complain about incorrect options

by ascobie (Initiate)
on Jun 17, 2013 at 15:31 UTC ( #1039398=perlquestion: print w/ replies, xml ) Need Help??
ascobie has asked for the wisdom of the Perl Monks concerning the following question:

I'm attempting to use the perl App::Cmd module and a simple test program works fine.

However, if I run the program with an --option that I haven't configured in the opt_spec function (of the sub command I'm invoking), it doesn't complain about an invalid option. I would expect it to do so. Instead it just quietly ignores that option.

I can't see anyway of configuring App::Cmd to complain about invalid options.

Is this possible, or is each sub-command expected to do the checking itself?

Thanks

Comment on How can I configure the perl App::Cmd module to complain about incorrect options
Re: How can I configure the perl App::Cmd module to complain about incorrect options
by tobyink (Abbot) on Jun 17, 2013 at 15:54 UTC

    If you pass an unrecognised option, App::Cmd doesn't complain, but it also doesn't ignore it! It adds it to the $args array.

    If you don't like this, the easiest thing is to create a subclass of App::Cmd::Command, and override validate_args to check for arguments that look like they were intended to be options. Then use your subclass instead of using App::Cmd::Command directly.

    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
      Great, thanks!

      Will give that a go.

Re: How can I configure the perl App::Cmd module to complain about incorrect options
by toolic (Chancellor) on Jun 17, 2013 at 15:56 UTC
    • Show the code you are using.
    • Show the actual output you get.
    • Show the output you expect to get.
    • Did you look though the code examples in the CPAN distribution (in the t/ directory, etc.)?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1039398]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2014-12-25 10:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (160 votes), past polls