Subject: | Short options are confused with flags |
Date: | Sat, 2 Sep 2017 23:18:17 +0000 |
To: | "bug-MooseX-App [...] rt.cpan.org" <bug-MooseX-App [...] rt.cpan.org> |
From: | Thiago Luiz Araujo Miller <thiago_leisrael [...] hotmail.com> |
Hi,
I am trying to build a command-line interface using this package
MooseX::App. It seems great with a lot of features and plugins!
However, I catched a probable bug. Let me detail:
My system: ArchLinux Kernel 4.12.8-2-ARCH
My perl: Perl v5.26.0
MooseX::App v1.38
In the command class:
option 'jobs' => (
is => 'rw',
isa => 'Int',
cmd_aliases => ['j']
);
sub run {
my $self shift;
say "jobs = ", $self->jobs;
}
Executing the script:
$: ./app.pl command --jobs=10
$: jobs = 10
$: ./app.pl command -j 10
$: jobs = 10
$: ./app.pl command --jobs
$: Missing value for 'jobs'
usage: ...
But, when the user do not pass the value for the short option 'j':
$: ./app.pl command -j
$: jobs = 1
I am not sure, but I think that it may be related to
MooseX::App::ParseArgv at line 125, where the module parses the
command-line arguments in a switch style with regular expressions. I
guess that when someone passes a short option without the required
value, it is treated as a flag:
when (m/^-([^-][[:alnum:]]*)$/)
And receives the value "1":
$options{$flag}->add_value(
1,
$position,
$element,
);
My workaround is do not use short options (cmd_aliases) for the time
being.
Thanks for your attention and my compliments for your great job!