https://github.com/polettix/app-command
Simplify command-line applications generation
https://github.com/polettix/app-command
Last synced: 4 months ago
JSON representation
Simplify command-line applications generation
- Host: GitHub
- URL: https://github.com/polettix/app-command
- Owner: polettix
- License: other
- Created: 2021-06-30T00:54:18.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-06-30T20:01:51.000Z (over 4 years ago)
- Last Synced: 2025-06-14T23:05:05.557Z (6 months ago)
- Language: Perl
- Size: 56.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: Changes
- License: LICENSE
- Support: support/podversion.pl
Awesome Lists containing this project
README
# NAME
App::Command - simplify command line applications generation
# VERSION
This document describes App::Command version {{\[ version \]}}.
# SYNOPSIS
In `lib/MyApp.pm`:
package MyApp;
use strict;
use Moo;
extends 'App::Command';
sub BUILD_help { return 'this is a fantastic app' }
sub BUILD_description { return 'it really is!' }
sub BUILD_parameters {
return [
{
name => 'foo',
help => 'foo for bar',
getopt => 'foo|f!',
environment => 'COMMAND1_FOO',
default => 1, # --no-foo
},
];
}
sub simple_commands {
my $self = shift;
return (
{
supports => [qw< show-foo show_foo >],
help => 'show the value of the foo option',
description => 'Well, show that value!',
execute => sub {
print {*STDOUT} "foo is ",
$self->configuration('foo') ? 'true' : 'false';
print {*STDOUT} "\n";
},
},
{
supports => [qw< roll die >],
help => 'roll a die',
description => 'roll a die, might be slightly biased though',
parameters => [
{
name => 'faces',
help => 'number of faces of the die',
getopt => 'faces|F=i',
environment => 'MYAPP_FACES',
default => 6,
},
],
execute => sub {
my $faces = shift->configuration('faces');
printf "%d\n", int(1 + rand $faces);
},
},
);
}
1;
In `script/myapp`:
use strict;
use MyApp;
MyApp->run(args => \@ARGV);
# DESCRIPTION
This library simplifies coding command-line applications, especially if they
should support sub-commands.
# COPYRIGHT AND LICENSE
Copyright (C) 2021 by Flavio Poletti
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
> [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.