App-Easer
view release on metacpan or search on metacpan
docs/templates/getting-started.pl view on Meta::CPAN
# specfetch => '+SpecFromHash', # default
# specfetch => '+SpecFromHashOrModule', # possible alternative
},
commands => {
MAIN => {
help => 'An application to do X',
description => 'An application to do X, easily',
# allow for configuration files
sources => '+SourcesWithFiles',
# 'config-files' => ["/etc/$APPNAME.json"],
options => [
{
getopt => 'config|c=s',
help => 'path to the configuration file',
environment => 1,
# default => "$ENV{HOME}/.$APPNAME.json",
},
],
children => [qw< foo bar >],
},
foo => {
help => 'An example sub-command',
description => 'An example sub-command, more details',
options => [
{
getopt => 'baz|b=s',
help => '',
environment => 1,
# default => '',
},
],
execute => '#foo',
},
bar => {
help => 'Another example sub-command',
description => 'Another example sub-command, more details',
options => [
{
getopt => 'galook|g=s',
help => '',
environment => 1,
# default => '',
},
],
execute => '#bar',
},
}
};
exit run($application, [@ARGV]);
package MyApp;
# implementation of sub-command foo
sub foo ($general, $config, $args) {
# $general is a hash reference to the overall application
# $config is a hash reference with options
# $args is an array reference with "residual" cmd line arguments
for my $key (sort { $a cmp $b } keys $config->%*) {
say "$key: $config->{$key}";
}
say "($args->@*)";
return;
}
# implementation of sub-command bar
sub bar ($general, $config, $args) {
say defined($config->{galook}) ? $config->{galook} : '*undef*';
return;
}
( run in 1.457 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )