I use App::Cmd for building my CLI apps.
Is it possible to implement subcommand like docker network inspect ? (assuming that inspect is subcommand)
I have following code for implementing command foo bar
$ cat bin/foo
#!/usr/bin/perl
use Foo;
Foo->run;
$ cat lib/Foo.pm
package Foo;
use App::Cmd::Setup -app;
1;
$ cat lib/Foo/Command/bar.pm
package Foo::Command::bar;
use App::Cmd::Setup -command;
sub execute {
print "Hello world\n";
}
1;
I implemented subcommand foo bar baz by modifying lib/Foo/Command/bar.pm as:
sub execute {
my ( $self, $opt, $args ) = @_;
my $subcommand = $args->[0];
if ( $subcommand eq 'baz' ) {
print "Subcommand baz is working\n";
}
...
}
Is there any better way ?
Big minus of $args->[0] approach is that you can not auto generate --help (foo bar will show same help as foo bar baz)
In other words, App::Cmd is sharpen for <bin_name> <command> [-?h] [long options...] call syntax, but I need <bin_name> <command> <subcommand> [-?h] [long options...] syntax.
P.S. I created Github repository for experiments