App::Spec(3)
π NAME π
App::Spec β Specification for commandline apps. This is user-contributed Perl documentation, and it's giving "spec sheet for your CLI bestie" energy. π«Ά
β¨ SYNOPSIS β¨
WARNING: This is still experimental. The spec is subject to change.
This module represents a specification of a command line tool. Currently it can read the spec from a YAML file or directly from a data structure in perl.
It uses the role App::Spec::Role::Command.
The App::Spec::Run module is the framework which will run the actual app.
Have a look at App::Spec::Tutorial for how to write an app.
In the examples directory you will find the app "myapp" which is supposed to demonstrate everything that App::Spec supports right now.
Your script:
use App::Spec;
my $spec = App::Spec->read("/path/to/myapp-spec.yaml");
my $run = $spec->runner;
$run->run;
# this is equivalent to
#my $run = App::Spec::Run->new(
# spec => $spec,
# cmd => Your::App->new,
#);
#$run->run;
Your App class:
package Your::App;
use base 'App::Spec::Run::Cmd';
sub command1 {
my ($self, $run) = @_;
my $options = $run->options;
my $param = $run->parameters;
# Do something
$run->out("Hello world!");
$run->err("oops");
# you can also use print directly
}
π¦ METHODS π¦
π read
my $spec = App::Spec->read("/path/to/myapp-spec.yaml");
π load_data
Takes a file, hashref or glob and returns generated appspec hashref.
my $hash = $class->load_data($file);
π
build
Builds objects out of the hashref.
my $appspec = App::Spec->build(%hash);
π§ runner
Returns an instance of your app class.
my $run = $spec->runner;
$run->run;
# this is equivalent to
my $run = App::Spec::Example::MyApp->new({
spec => $spec,
});
$run->run;
πΈ usage
Returns usage output for the specified subcommands:
my $usage = $spec->usage(
commands => ["subcommand1","subcommand2"],
);
π₯ generate_completion
Generates shell completion script for the spec.
my $completion = $spec->generate_completion(
shell => "zsh",
);
π make_getopt
Returns options for Getopt::Long.
my @getopt = $spec->make_getopt($global_options, \%options, $option_specs);
π abstract, appspec, class, description, has_subcommands, markup, name, options, parameters, subcommands, title
Accessors for the things defined in the spec (file).
π SEE ALSO π
App::AppSpecβ Utilities forApp::Specauthors.
π LICENSE π
This library is free software and may be distributed under the same terms as perl itself.
That's the whole thing, bestie π
β brought to you by perl v5.42.0 and dated 2025-03-26. App::Spec(3) out. πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-App-Spec 0.15.0-bp160.1.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms