The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Term::CLI::Role::ArgumentSet - Role for (sub-)commands in Term::CLI

VERSION

version 0.04004

SYNOPSIS

 package Term::CLI::Command {

    use Moo;

    with('Term::CLI::Role::ArgumentSet');

    ...
 };

 my $cmd = Term::CLI::Command->new( ... );

 $cmd->add_argument( Term::CLI::Argument->new(...) );

 say "argument names:", join(', ', $cmd->argument_names);

DESCRIPTION

Role for Term::CLI::Command(3p) elements to represent a set of Term::CLI::Argument(3p) objects.

This role is consumed by Term::CLI::Command(3p).

ATTRIBUTES

This role defines two additional attributes:

arguments => ArrayRef

Reference to an array containing Term::CLI::Argument object instances that describe the parameters that the command takes, or undef.

Note that the elements of the array are copied over to an internal array, so modifications to the ArrayRef will not be seen.

ACCESSORS AND PREDICATES

has_arguments

Predicate function that returns whether or not any Term::CLI::Arguments have been added.

arguments

Return the list of Term::CLI::Argument object references that are owned by this object.

METHODS

set_arguments ( ARG, ... )

Reset the list of arguments to (ARG, ...). Each ARG should be a reference to a Term::CLI::Argument object.

add_argument ( ARG, ... )

Add ARG(s) to the argument set. Each ARG should be a reference to a Term::CLI::Argument object.

argument_names

Return the list of (sub-)command names (in the order they were specified).

find_matches ( Str )

Return a list of all commands in this object that match the Str prefix.

find_command ( Str )

Check whether Str uniquely matches a command in this Term::CLI object. Returns a reference to the appropriate Term::CLI::Command object if successful; otherwise, it sets the objects error field and returns undef.

Example:

    my $sub_cmd = $cmd->find_command($prefix);
    die $cmd->error unless $sub_cmd;
try_callback ( ARGS )

Wrapper function that will call the object's callback function if it has been set, otherwise simply returns its arguments.

SEE ALSO

Term::CLI(3p), Term::CLI::Command(3p).

AUTHOR

Steven Bakker <sbakker@cpan.org>, 2018.

COPYRIGHT AND LICENSE

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.