Term::CLI::Command - Class for (sub-)commands in Term::CLI
version 0.04003
use Term::CLI::Command; use Term::CLI::Argument::Filename; use Data::Dumper; my $copy_cmd = Term::CLI::Command->new( name => 'copy', options => [ 'verbose!' ], arguments => [ Term::CLI::Argument::Filename->new(name => 'src'), Term::CLI::Argument::Filename->new(name => 'dst'), ], callback => sub { my ($self, %args) = @_; print Data::Dumper->Dump([\%args], ['args']); return (%args, status => 0); } );
Class for command elements in Term::CLI(3p).
Term::CLI::Element(3p).
Term::CLI::Role::ArgumentSet(3p), Term::CLI::Role::CommandSet(3p), Term::CLI::Role::HelpText(3p).
Create a new Term::CLI::Command object and return a reference to it.
The name attribute is required.
Other attributes are:
Reference to an array containing Term::CLI::Argument(3p) object instances that describe the parameters that the command takes, or undef.
undef
See also Term::CLI::Role::ArgumentSet.
Reference to a subroutine that should be called when the command is executed, or undef.
Reference to an array containing Term::CLI::Command object instances that describe the sub-commands that the command takes, or undef.
Term::CLI::Command
Reference to an array containing command options in Getopt::Long(3p) style, or undef.
Extended description of the command.
See also Term::CLI::Role::HelpText.
Short description of the command.
Static usage summary of the command.
(NOTE: You will rarely have to specify this, as it can be determined automatically.)
This class inherits all the attributes and accessors of Term::CLI::Element(3p), Term::CLI::Role::CommandSet(3p), Term::CLI::Role::HelpText(3p), and Term::CLI::Role::ArgumentSet(3p), most notably:
See has_arguments in Term::CLI::Role::ArgumentSet.
See has_callback in Term::CLI::Role::CommandSet.
See has_commands in Term::CLI::Role::CommandSet.
See arguments in Term::CLI::Role::ArgumentSet.
Returns a list of Term::CLI::Argument object instances.
Term::CLI::Argument
See commands in Term::CLI::Role::CommandSet.
Returns a list of Term::CLI::Command object instances.
See callback in Term::CLI::Role::CommandSet.
See description in Term::CLI::Role::HelpText.
See summary in Term::CLI::Role::HelpText.
Return the list of argument names, in the original order.
Return the list of (sub-)command names, sorted alphabetically.
Check whether CMD is a sub-command of this command. If so, return the appropriate Term::CLI::Command reference; otherwise, return undef.
Predicate functions that return whether or not the associated attribute has been set.
ArrayRef with command-line options in Getopt::Long(3p) format.
CLI is a reference to the top-level Term::CLI instance.
The WORD arguments make up the parameters to this command. Given those, this method attempts to generate possible completions for the last WORD in the list.
The method can complete options, sub-commands, and arguments. Completions of commands and arguments is delegated to the appropriate Term::CLI::Command and Term::CLI::Argument instances, resp.
Return a list of all command line options for this command. Long options are prefixed with --, and one-letter options are prefixed with -.
--
-
Example:
$cmd->options( [ 'verbose|v+', 'debug|d', 'help|h|?' ] ); say join(' ', $cmd->option_names); # output: --debug --help --verbose -? -d -h -v
This method is called by Term::CLI::execute. It should not be called directly.
It accepts the same list of parameters as the command callback function (see Term::CLI::Role::CommandSet), and returns the same structure.
The arguments ArrayRef should contain the words on the command line that have not been parsed yet.
arguments
Depending on whether the object has sub-commands or arguments, the rest of the line is parsed (possibly handing off to another sub-command), and the results are passed to the command's callback function.
Term::CLI::Argument(3p), Term::CLI::Element(3p), Term::CLI::Role::ArgumentSet(3p), Term::CLI::Role::CommandSet(3p), Term::CLI::Role::HelpText(3p), Term::CLI(3p), Getopt::Long(3p).
Steven Bakker <sbakker@cpan.org>, 2018.
Copyright (c) 2018 Steven Bakker
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See "perldoc perlartistic."
This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
To install Term::CLI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Term::CLI
CPAN shell
perl -MCPAN -e shell install Term::CLI
For more information on module installation, please visit the detailed CPAN module installation guide.