Commandable::Command(3pm) | User Contributed Perl Documentation | Commandable::Command(3pm) |
"Commandable::Command" - represent metadata for an invokable command
The following simple methods return metadata fields about the command
$name = $command->name; $desc = $command->description;
Strings giving the short name (to be used on a commandline), and descriptive text for the command.
@args = $command->arguments;
A (possibly-empty) list of argument metadata structures.
%opts = $command->options;
A (possibly-empty) kvlist of option metadata structures.
$pkg = $command->packaage;
The package name as a plain string.
$sub = $command->code;
A CODE reference to the code actually implementing the command.
$conf = $command->config;
A HASH reference to the configuration of the command.
@vals = $command->parse_invocation( $cinv );
Parses values out of a Commandable::Invocation instance according to the specification for the command's arguments. Returns a list of perl values suitable to pass into the function implementing the command.
This method will throw an exception if mandatory arguments are missing.
Each argument specification is given by an object having the following structure:
$name = $argspec->name; $desc = $argspec->description;
Text strings for the user, used to generate the help text.
$bool = $argspec->optional;
If false, the option is mandatory and an error is raised if no value is provided for it. If true, it is optional and if absent an "undef" will passed instead.
$bool = $argspec->slurpy;
If true, the argument will be passed as an ARRAY reference containing the entire remaining list of tokens provided by the user.
Each option specification is given by an object having the following structure:
$name = $optspec->name;
A string giving the name of the option. This is the name it will be given in the options hash provided to the command subroutine.
@names = $optspec->names;
A list containing the name plus all the aliases this option is known by.
$desc = $optspec->description;
A text string containing information for the user, used to generate the help text.
$mode = $optspec->mode;
A string that describes the behaviour of the option.
"set" options do not expect a value to be suppled by the user, and will store a true value in the options hash if present.
"value" options take a value from the rest of the token, or the next token.
--opt=value --opt value
"multi_value" options can be supplied more than once; values are pushed into an ARRAY reference which is passed in the options hash.
"inc" options may be supplied more than once; each occurance will increment the stored value by one.
$val = $optspec->default;
A value to provide in the options hash if the user did not specify a different one.
$bool = $optspec->negatable;
If true, also accept a "--no-OPT" option to reset the value of the option to "undef".
$type = $optspec->typespec;
If defined, gives a type specification that any user-supplied value must conform to.
The "i" type must be a string giving a (possibly-negative) decimal integer.
Paul Evans <leonerd@leonerd.org.uk>
2023-10-01 | perl v5.36.0 |