Permalink
Browse files

send error to stderr on unknown command

  • Loading branch information...
1 parent cc51f21 commit 735798786e7d130a1d9fac2192d8898b0c92d611 @rjbs committed Jan 31, 2013
Showing with 19 additions and 8 deletions.
  1. +2 −0 Changes
  2. +1 −0 dist.ini
  3. +1 −1 lib/App/Cmd.pm
  4. +15 −7 lib/App/Cmd/Command/commands.pm
View
2 Changes
@@ -1,6 +1,8 @@
Revision history for App-Cmd
{{$NEXT}}
+ when answering "Unknown subcommand," the commands list is sent ot
+ STDERR (#75652)
0.319 2013-01-25 18:18:21 America/New_York
Enable --help option for App::Cmd::Simple (thanks, Ryan Thompson!)
View
1 dist.ini
@@ -4,6 +4,7 @@ license = Perl_5
copyright_holder = Ricardo Signes
[@RJBS]
+github_issues = 1
[Prereqs]
Getopt::Long::Descriptive = 0.084
View
2 lib/App/Cmd.pm
@@ -407,7 +407,7 @@ sub _bad_command {
# This should be class data so that, in Bizarro World, two App::Cmds will not
# conflict.
our $_bad++;
- $self->prepare_command("commands");
+ $self->prepare_command(qw(commands --stderr));
}
END { exit 1 if our $_bad };
View
22 lib/App/Cmd/Command/commands.pm
@@ -24,15 +24,17 @@ group is set off by blank lines.
=cut
sub execute {
- my ($self) = @_;
+ my ($self, $opt, $args) = @_;
+
+ my $target = $opt->stderr ? *STDERR : *STDOUT;
local $@;
- eval { print $self->app->_usage_text . "\n" };
+ eval { print { $target } $self->app->_usage_text . "\n" };
- print "Available commands:\n\n";
+ print { $target } "Available commands:\n\n";
my @primary_commands =
- map { ($_->command_names)[0] }
+ map { ($_->command_names)[0] }
$self->app->command_plugins;
my @cmd_groups = $self->sort_commands(@primary_commands);
@@ -44,9 +46,9 @@ sub execute {
foreach my $cmd_set (@cmd_groups) {
for my $command (@$cmd_set) {
my $abstract = $self->app->plugin_for($command)->abstract;
- printf "%${fmt_width}s: %s\n", $command, $abstract;
+ printf { $target } "%${fmt_width}s: %s\n", $command, $abstract;
}
- print "\n";
+ print { $target } "\n";
}
}
@@ -73,8 +75,14 @@ sub sort_commands {
return (\@head, \@tail);
}
+sub opt_spec {
+ return (
+ [ 'stderr' => 'hidden' ],
+ );
+}
+
sub description {
-"This command will list all of commands available and their abstracts.\n";
+ "This command will list all of commands available and their abstracts.\n";
}

0 comments on commit 7357987

Please sign in to comment.