Skip to content

Commit

Permalink
fix for required option field
Browse files Browse the repository at this point in the history
  • Loading branch information
dann committed Jul 13, 2008
1 parent 38cb682 commit 675affc
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/MooseX/App/Cmd/Command.pm
Expand Up @@ -30,7 +30,7 @@ sub _process_args {

my %processed = $class->_parse_argv(
argv => $args,
options => [ $class->_attrs_to_options( @params ) ],
options => [ $class->_attrs_to_options() ],
);

return (
Expand Down
20 changes: 17 additions & 3 deletions t/basic.t
Expand Up @@ -3,7 +3,7 @@
use strict;
use warnings;

use Test::More tests => 10;
use Test::More tests => 12;

use lib 't/lib';

Expand All @@ -15,15 +15,18 @@ isa_ok($cmd, 'Test::MyCmd');

is_deeply(
[ sort $cmd->command_names ],
[ sort qw(help --help -h -? commands frob frobulate justusage stock) ],
[ sort qw(help --help -h -? commands frob frobulate justusage stock bark) ],
"got correct list of registered command names",
);

use Data::Dumper;
Dumper $cmd->command_plugins;
is_deeply(
[ sort $cmd->command_plugins ],
[ qw(
App::Cmd::Command::commands
App::Cmd::Command::help
Test::MyCmd::Command::bark
Test::MyCmd::Command::frobulate
Test::MyCmd::Command::justusage
Test::MyCmd::Command::stock
Expand Down Expand Up @@ -63,6 +66,17 @@ is_deeply(
like($@, qr/mandatory method/, "un-subclassed &run leads to death");
}

{
local @ARGV = qw(bark);
eval { $cmd->run };

like(
$@,
qr/Required option missing: wow/,
"required option fileld is missing",
);
}

SKIP: {
my $have_TO = eval { require Test::Output; 1; };
print $@;
Expand All @@ -72,7 +86,7 @@ SKIP: {

my ($output) = Test::Output::output_from(sub { $cmd->run });

for my $name (qw(commands frobulate justusage stock)) {
for my $name (qw(commands frobulate justusage stock bark)) {
like($output, qr/^\s+\Q$name\E/sm, "$name plugin in listing");
}
}
25 changes: 25 additions & 0 deletions t/lib/Test/MyCmd/Command/bark.pm
@@ -0,0 +1,25 @@
package Test::MyCmd::Command::bark;
use Moose;

extends qw(MooseX::App::Cmd::Command);

=head1 NAME
Test::MyCmd::Command::bark - required field is used
=cut

has wow => (
isa => "Str",
is => "ro",
required => 1,
documentation => "required option field",
);

sub run {
my ($self, $opt, $arg) =@_;

die "my dog name barks " . $self->wow . "\n";
}

1;

0 comments on commit 675affc

Please sign in to comment.