Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
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
Replies are listed 'Best First'.
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 (Bishop) 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 drinking their drinks and smoking their pipes about the Monastery: (12)
As of 2015-07-31 07:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (275 votes), past polls