NAME

Venus::Cli - Cli Class

ABSTRACT

Cli Class for Perl 5

SYNOPSIS

package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

# $cli->usage;

# ...

# $cli->parsed;

# {help => 1}

DESCRIPTION

This package provides a superclass and methods for creating simple yet robust command-line interfaces.

ATTRIBUTES

This package has the following attributes:

name

name(string $name) (string)

The name attribute is read-write, accepts (string) values, and is optional.

Since 4.15

name example 1
# given: synopsis

package main;

my $name = $cli->name("mycli");

# "mycli"
name example 2
# given: synopsis

# given: example-1 name

package main;

$name = $cli->name;

# "mycli"

version

version(string $version) (string)

The version attribute is read-write, accepts (string) values, and is optional.

Since 4.15

version example 1
# given: synopsis

package main;

my $version = $cli->version("0.0.1");

# "0.0.1"
version example 2
# given: synopsis

# given: example-1 version

package main;

$version = $cli->version;

# "0.0.1"

summary

summary(string $summary) (string)

The summary attribute is read-write, accepts (string) values, and is optional.

Since 4.15

summary example 1
# given: synopsis

package main;

my $summary = $cli->summary("Example summary");

# "Example summary"
summary example 2
# given: synopsis

# given: example-1 summary

package main;

$summary = $cli->summary;

# "Example summary"

description

description(string $description) (string)

The description attribute is read-write, accepts (string) values, and is optional.

Since 4.15

description example 1
# given: synopsis

package main;

my $description = $cli->description("Example description");

# "Example description"
description example 2
# given: synopsis

# given: example-1 description

package main;

$description = $cli->description;

# "Example description"
header(string $header) (string)

The header attribute is read-write, accepts (string) values, and is optional.

Since 4.15

header example 1
# given: synopsis

package main;

my $header = $cli->header("Example header");

# "Example header"
header example 2
# given: synopsis

# given: example-1 header

package main;

$header = $cli->header;

# "Example header"
footer(string $footer) (string)

The footer attribute is read-write, accepts (string) values, and is optional.

Since 4.15

# given: synopsis

package main;

my $footer = $cli->footer("Example footer");

# "Example footer"
# given: synopsis

# given: example-1 footer

package main;

$footer = $cli->footer;

# "Example footer"

arguments

arguments(hashref $arguments) (hashref)

The arguments attribute is read-write, accepts (hashref) values, and is optional.

Since 4.15

arguments example 1
# given: synopsis

package main;

my $arguments = $cli->arguments({});

# {}
arguments example 2
# given: synopsis

# given: example-1 arguments

package main;

$arguments = $cli->arguments;

# {}

options

options(hashref $options) (hashref)

The options attribute is read-write, accepts (hashref) values, and is optional.

Since 4.15

options example 1
# given: synopsis

package main;

my $options = $cli->options({});

# {}
options example 2
# given: synopsis

# given: example-1 options

package main;

$options = $cli->options;

# {}

choices

choices(hashref $choices) (hashref)

The choices attribute is read-write, accepts (hashref) values, and is optional.

Since 4.15

choices example 1
# given: synopsis

package main;

my $choices = $cli->choices({});

# {}
choices example 2
# given: synopsis

# given: example-1 choices

package main;

$choices = $cli->choices;

# {}

data

data(hashref $data) (hashref)

The data attribute is read-write, accepts (hashref) values, and is optional.

Since 4.15

data example 1
# given: synopsis

package main;

my $data = $cli->data({});

# {}
data example 2
# given: synopsis

# given: example-1 data

package main;

$data = $cli->data;

# {}

INHERITS

This package inherits behaviors from:

Venus::Kind::Utility

INTEGRATES

This package integrates behaviors from:

Venus::Role::Printable

METHODS

This package provides the following methods:

args

args() (Venus::Args)

The args method returns the list of parsed command-line arguments as a Venus::Args object.

Since 4.15

args example 1
# given: synopsis

package main;

my $args = $cli->args;

# bless(..., "Venus::Args")
args example 2
# given: synopsis

package main;

$cli->parse('hello', 'world');

my $args = $cli->args;

# bless(..., "Venus::Args")

# $args->get(0);

# $args->get(1);

argument

argument(string $name, hashref $data) (maybe[hashref])

The argument method registers and returns the configuration for the argument specified. The method takes a name (argument name) and a hashref of configuration values. The possible configuration values are as follows:

  • The name key holds the name of the argument.

  • The label key holds the name of the argument as it should be displayed in the CLI help text.

  • The help key holds the help text specific to this argument.

  • The default key holds the default value that should used if no value for this argument is provided to the CLI.

  • The multiples key denotes whether this argument can be used more than once, to collect multiple values, and holds a 1 if multiples are allowed and a 0 otherwise.

  • The prompt key holds the question or statement that should be presented to the user of the CLI if no value has been provided for this argument and no default value has been set.

  • The range key holds a two-value arrayref where the first value is the starting index and the second value is the ending index. These values are used to select values from the parsed arguments array as the value(s) for this argument. This value is ignored if the multiples key is set to 0.

  • The required key denotes whether this argument is required or not, and holds a 1 if required and a 0 otherwise.

  • The type key holds the data type of the argument expected. Valid values are "number", "string", "float", "boolean", or "yesno". Note: Valid boolean values are 1, 0, "true", and "false".

Since 4.15

argument example 1
# given: synopsis

package main;

my $argument = $cli->argument('name', {
  label => 'Name',
  help => 'The name of the user',
  default => 'Unknown',
  required => 1,
  type => 'string'
});

# {
#   name => 'name',
#   label => 'Name',
#   help => 'The name of the user',
#   default => 'Unknown',
#   multiples => 0,
#   prompt => undef,
#   range => undef,
#   required => 1,
#   type => 'string',
#   index => 0,
#   wants => 'string',
# }

argument_choice

argument_choice(string $name) (arrayref)

The argument_choice method returns the parsed argument value only if it corresponds to a registered choice associated with the named argument. If the value (or any of the values) doesn't map to a choice, this method will return an empty arrayref. Returns a list in list context.

Since 4.15

argument_choice example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $argument_choice = $cli->argument_choice;

# []
argument_choice example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  range => '0',
  type => 'string',
});

$cli->parse('stdin');

my $argument_choice = $cli->argument_choice('input');

# []
argument_choice example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  range => '0',
  type => 'string',
});

$cli->choice('stdin', {
  argument => 'input',
});

$cli->choice('stdout', {
  argument => 'input',
});

$cli->parse('stdin');

my $argument_choice = $cli->argument_choice('input');

# ['stdin']
argument_choice example 4
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  multiples => true,
  range => '0:',
  type => 'string',
});

$cli->choice('stdin', {
  argument => 'input',
});

$cli->choice('stdout', {
  argument => 'input',
});

$cli->parse('stdin', 'stdout');

my $argument_choice = $cli->argument_choice('input');

# ['stdin', 'stdout']

argument_choices

argument_choices(string $name) (arrayref)

The argument_choices method returns all registered choices associated with the argument named. Returns a list in list context.

Since 4.15

argument_choices example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $argument_choices = $cli->argument_choices;

# []
argument_choices example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  type => 'string',
});

my $argument_choices = $cli->argument_choices('input');

# []
argument_choices example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  type => 'string',
});

$cli->choice('stdin', {
  argument => 'input',
});

my $argument_choices = $cli->argument_choices('input');

# [{
#   name => 'stdin',
#   label => undef,
#   help => 'Expects a string value',
#   argument => 'input',
#   index => 0,
#   wants => 'string',
# }]

argument_count

argument_count() (number)

The argument_count method returns the count of registered arguments.

Since 4.15

argument_count example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $argument_count = $cli->argument_count;

# 0
argument_count example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  type => 'string',
});

$cli->argument('output', {
  type => 'string',
});

my $argument_count = $cli->argument_count;

# 2

argument_default

argument_default(string $name) (string)

The argument_default method returns the default configuration value for the named argument.

Since 4.15

argument_default example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $argument_default = $cli->argument_default;

# ""
argument_default example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  default => 'stdin',
});

my $argument_default = $cli->argument_default('input');

# "stdin"

argument_errors

argument_errors(string $name) (within[arrayref, Venus::Validate])

The argument_errors method returns a list of "issues", if any, for each value returned by "argument_value" for the named argument. Returns a list in list context.

Since 4.15

argument_errors example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $argument_errors = $cli->argument_errors;

# []
argument_errors example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  range => '0',
  type => 'string',
});

$cli->parse('hello');

my $argument_errors = $cli->argument_errors('input');

# []
argument_errors example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  range => '0',
  type => 'number',
});

$cli->parse('hello');

my $argument_errors = $cli->argument_errors('input');

# [['type', ['number']]]

argument_help

argument_help(string $name) (string)

The argument_help method returns the help configuration value for the named argument.

Since 4.15

argument_help example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $argument_help = $cli->argument_help;

# ""
argument_help example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  help => 'Example help text',
});

my $argument_help = $cli->argument_help('input');

# "Example help text"

argument_label

argument_label(string $name) (string)

The argument_label method returns the label configuration value for the named argument.

Since 4.15

argument_label example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $argument_label = $cli->argument_label;

# ""
argument_label example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  label => 'Input',
});

my $argument_label = $cli->argument_label('input');

# "Input"

argument_list

argument_list(string $name) (within[arrayref, hashref])

The argument_list method returns a list of registered argument configurations. Returns a list in list context.

Since 4.15

argument_list example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $argument_list = $cli->argument_list;

# []
argument_list example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  type => 'string',
});

my $argument_list = $cli->argument_list;

# [{
#   name => 'input',
#   label => undef,
#   help => 'Expects a string value',
#   default => undef,
#   multiples => 0,
#   prompt => undef,
#   range => undef,
#   required => false,
#   type => 'string',
#   index => 0,
#   wants => 'string',
# }]

argument_multiples

argument_multiples(string $name) (boolean)

The argument_multiples method returns the multiples configuration value for the named argument.

Since 4.15

argument_multiples example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $argument_multiples = $cli->argument_multiples;

# false
argument_multiples example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  multiples => true,
});

my $argument_multiples = $cli->argument_multiples('input');

# true

argument_name

argument_name(string $name) (string)

The argument_name method returns the name configuration value for the named argument.

Since 4.15

argument_name example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $argument_name = $cli->argument_name;

# ""
argument_name example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  name => 'INPUT',
});

my $argument_name = $cli->argument_name('input');

# ""
argument_name example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  name => 'INPUT',
});

my $argument_name = $cli->argument_name('INPUT');

# "INPUT"

argument_names

argument_names(string $name) (within[arrayref, string])

The argument_names method returns the names (keys) of registered arguments in the order declared. Returns a list in list context.

Since 4.15

argument_names example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $argument_names = $cli->argument_names;

# []
argument_names example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  type => 'string',
});

$cli->argument('output', {
  type => 'string',
});

my $argument_names = $cli->argument_names;

# ['input', 'output']
argument_names example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('output', {
  type => 'string',
});

$cli->argument('input', {
  type => 'string',
});

my $argument_names = $cli->argument_names;

# ['output', 'input']

argument_prompt

argument_prompt(string $name) (string)

The argument_prompt method returns the prompt configuration value for the named argument.

Since 4.15

argument_prompt example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $argument_prompt = $cli->argument_prompt;

# ""
argument_prompt example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  prompt => 'Example prompt',
});

my $argument_prompt = $cli->argument_prompt('input');

# "Example prompt"

argument_range

argument_range(string $name) (string)

The argument_range method returns the range configuration value for the named argument.

Since 4.15

argument_range example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $argument_range = $cli->argument_range;

# ""
argument_range example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  range => '0',
});

my $argument_range = $cli->argument_range('input');

# "0"
argument_range example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  range => '0:5',
});

my $argument_range = $cli->argument_range('input');

# "0:5"

argument_required

argument_required(string $name) (boolean)

The argument_required method returns the required configuration value for the named argument.

Since 4.15

argument_required example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $argument_required = $cli->argument_required;

# false
argument_required example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  required => true,
});

my $argument_required = $cli->argument_required('input');

# true

argument_type

argument_type(string $name) (string)

The argument_type method returns the type configuration value for the named argument. Valid values are as follows:

  • number

  • string

  • float

  • boolean - Note: Valid boolean values are 1, 0, "true", and "false".

  • yesno

Since 4.15

argument_type example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $argument_type = $cli->argument_type;

# ""
argument_type example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  type => 'boolean',
});

my $argument_type = $cli->argument_type('input');

# "boolean"

argument_validate

argument_validate(string $name) (Venus::Validate | within[arrayref, Venus::Validate])

The argument_validate method returns a Venus::Validate object for each value returned by "argument_value" for the named argument. Returns a list in list context.

Since 4.15

argument_validate example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $argument_validate = $cli->argument_validate;

# []
argument_validate example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  multiples => true,
  range => '0',
  type => 'string',
});

my $argument_validate = $cli->argument_validate('input');

# [bless(..., "Venus::Validate")]
argument_validate example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  multiples => false,
  range => '0',
  type => 'string',
});

my $argument_validate = $cli->argument_validate('input');

# bless(..., "Venus::Validate")
argument_validate example 4
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  multiples => true,
  range => '0:',
  type => 'string',
});

$cli->parse('hello', 'world');

my $argument_validate = $cli->argument_validate('input');

# [bless(..., "Venus::Validate"), bless(..., "Venus::Validate")]

argument_value

argument_value(string $name) (any)

The argument_value method returns the parsed argument value for the named argument.

Since 4.15

argument_value example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $argument_value = $cli->argument_value;

# undef
argument_value example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  multiples => false,
  range => '0:',
  type => 'string',
});

$cli->parse('hello', 'world');

my $argument_value = $cli->argument_value('input');

# "hello"
argument_value example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  multiples => true,
  range => '0:',
  type => 'string',
});

$cli->parse('hello', 'world');

my $argument_value = $cli->argument_value('input');

# ["hello", "world"]

argument_wants

argument_wants(string $name) (string)

The argument_wants method returns the wants configuration value for the named argument.

Since 4.15

argument_wants example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $argument_wants = $cli->argument_wants;

# ""
argument_wants example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  wants => 'string',
});

my $argument_wants = $cli->argument_wants('input');

# "string"

assigned_arguments

assigned_arguments() (hashref)

The assigned_arguments method gets the values for the registered arguments.

Since 4.15

assigned_arguments example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->argument('extra', {
  range => '0:',
  type => 'string',
});

local @ARGV = qw(--input stdin --output stdout hello world);

my $assigned_arguments = $cli->assigned_arguments;

# {extra => 'hello'}
assigned_arguments example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->argument('extra', {
  multiples => true,
  range => '0:',
  type => 'string',
});

local @ARGV = qw(--input stdin --output stdout hello world);

my $assigned_arguments = $cli->assigned_arguments;

# {extra => ['hello', 'world']}

assigned_options

assigned_options() (hashref)

The assigned_options method gets the values for the registered options.

Since 4.15

assigned_options example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->argument('extra', {
  range => '0:',
  type => 'string',
});

local @ARGV = qw(--input stdin --output stdout hello world);

my $assigned_options = $cli->assigned_options;

# {input => 'stdin', output => 'stdout'}
assigned_options example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  multiples => true,
  type => 'string',
});

$cli->option('output', {
  multiples => true,
  type => 'string',
});

$cli->argument('extra', {
  range => '0:',
  type => 'string',
});

local @ARGV = qw(--input stdin --output stdout hello world);

my $assigned_options = $cli->assigned_options;

# {input => ['stdin'], output => ['stdout']}

boolean

boolean(string $method, any @args) (any)

The boolean method is a configuration dispatcher and shorthand for {'type', 'boolean'}. It returns the data or dispatches to the next configuration dispatcher based on the name provided and merges the configurations produced.

Since 4.15

boolean example 1
# given: synopsis

package main;

my $boolean = $cli->boolean;

# {type => 'boolean'}
boolean example 2
# given: synopsis

package main;

my $boolean = $cli->boolean(undef, {required => true});

# {type => 'boolean', required => true}
boolean example 3
# given: synopsis

package main;

my $boolean = $cli->boolean('option', 'example');

# {
#   name => 'example',
#   label => undef,
#   help => 'Expects a boolean value',
#   default => undef,
#   aliases => [],
#   multiples => 0,
#   prompt => undef,
#   range => undef,
#   required => 1,
#   type => 'boolean',
#   index => 0,
#   wants => 'boolean',
# }

choice

choice(string $name, hashref $data) (maybe[hashref])

The choice method registers and returns the configuration for the choice specified. The method takes a name (choice name) and a hashref of configuration values. The possible configuration values are as follows:

  • The name key holds the name of the argument.

  • The label key holds the name of the argument as it should be displayed in the CLI help text.

  • The help key holds the help text specific to this argument.

  • The argument key holds the name of the argument that this choice is a value for.

  • The wants key holdd the text to be used as a value placeholder in the CLI help text.

Since 4.15

choice example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  range => '0',
  type => 'string',
});

my $choice = $cli->choice('stdin', {
  argument => 'input',
});

# {
#   name => 'stdin',
#   label => undef,
#   help => undef,
#   argument => 'input',
#   index => 0,
#   wants => 'string',
# }

choice_argument

choice_argument(string $name) (hashref)

The choice_argument method returns the argument configuration corresponding with the argument value of the named choice.

Since 4.15

choice_argument example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  type => 'string',
});

$cli->choice('stdin', {
  argument => 'input',
});

my $choice_argument = $cli->choice_argument('stdin');

# {
#   name => 'input',
#   label => undef,
#   help => 'Expects a string value',
#   default => undef,
#   multiples => 0,
#   prompt => undef,
#   range => undef,
#   required => 0,
#   type => 'string',
#   index => 0,
#   wants => 'string',
# }

choice_count

choice_count() (number)

The choice_count method returns the count of registered choices.

Since 4.15

choice_count example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $choice_count = $cli->choice_count;

# 0
choice_count example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  range => '0:',
  type => 'string',
});

$cli->choice('file', {
  argument => 'input',
});

$cli->choice('stdin', {
  argument => 'input',
});

my $choice_count = $cli->choice_count;

# 2

choice_default

choice_default(string $name) (string)

The choice_default method returns the default configuration value for the argument corresponding to the named choice.

Since 4.15

choice_default example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  default => 'file',
  type => 'string',
});

$cli->choice('stdin', {
  argument => 'input',
});

my $choice_default = $cli->choice_default('stdin');

# "file"

choice_errors

choice_errors(string $name) (within[arrayref, Venus::Validate])

The choice_errors method returns a list of "issues", if any, for each value returned by "choice_value" for the named choice. Returns a list in list context.

Since 4.15

choice_errors example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $choice_errors = $cli->choice_errors;

# []
choice_errors example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  range => '0',
  type => 'string',
});

$cli->choice('stdin', {
  argument => 'input',
});

$cli->parse('hello');

my $choice_errors = $cli->choice_errors('stdin');

# []
choice_errors example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  range => '0',
  type => 'number',
});

$cli->choice('stdin', {
  argument => 'input',
});

$cli->parse('hello');

my $choice_errors = $cli->choice_errors('stdin');

# [['type', ['number']]]

choice_help

choice_help(string $name) (string)

The choice_help method returns the help configuration value the named choice.

Since 4.15

choice_help example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $choice_help = $cli->choice_help;

# ""
choice_help example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  type => 'string',
});

$cli->choice('stdin', {
  argument => 'input',
  help => 'Example help',
});

my $choice_help = $cli->choice_help('stdin');

# "Example help"

choice_label

choice_label(string $name) (string)

The choice_label method returns the label configuration value for the named choice.

Since 4.15

choice_label example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $choice_label = $cli->choice_label;

# ""
choice_label example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  type => 'string',
});

$cli->choice('stdin', {
  argument => 'input',
  label => 'Standard input',
});

my $choice_label = $cli->choice_label('stdin');

# "Standard input"

choice_list

choice_list(string $name) (within[arrayref, hashref])

The choice_list method returns a list of registered choice configurations. Returns a list in list context.

Since 4.15

choice_list example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $choice_list = $cli->choice_list;

# []
choice_list example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  type => 'string',
});

$cli->choice('stdin', {
  argument => 'input',
});

my $choice_list = $cli->choice_list;

# [{
#   name => 'stdin',
#   label => undef,
#   help => 'Expects a string value',
#   argument => 'input',
#   index => 0,
#   wants => 'string',
# }]

choice_multiples

choice_multiples(string $name) (boolean)

The choice_multiples method returns the multiples configuration value for the argument corresponding to the named choice.

Since 4.15

choice_multiples example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $choice_multiples = $cli->choice_multiples;

# false
choice_multiples example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  multiples => true,
  type => 'string',
});

$cli->choice('stdin', {
  argument => 'input',
});

my $choice_multiples = $cli->choice_multiples('stdin');

# true

choice_name

choice_name(string $name) (string)

The choice_name method returns the name configuration value for the named choice.

Since 4.15

choice_name example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $choice_name = $cli->choice_name;

# ""
choice_name example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  type => 'string',
});

$cli->choice('stdin', {
  name => 'STDIN',
  argument => 'input',
});

my $choice_name = $cli->choice_name('stdin');

# "STDIN"

choice_names

choice_names(string $name) (within[arrayref, string])

The choice_names method returns the names (keys) of registered choices in the order declared. Returns a list in list context.

Since 4.15

choice_names example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $choice_names = $cli->choice_names;

# []
choice_names example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  type => 'string',
});

$cli->choice('file', {
  argument => 'input',
});

$cli->choice('stdin', {
  argument => 'input',
});

my $choice_names = $cli->choice_names;

# ['file', 'stdin']
choice_names example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  type => 'string',
});

$cli->choice('stdin', {
  argument => 'input',
});

$cli->choice('file', {
  argument => 'input',
});

my $choice_names = $cli->choice_names;

# ['stdin', 'file']

choice_prompt

choice_prompt(string $name) (string)

The choice_prompt method returns the prompt configuration value for the argument corresponding to the named choice.

Since 4.15

choice_prompt example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $choice_prompt = $cli->choice_prompt;

# ""
choice_prompt example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  prompt => 'Example prompt',
  type => 'string',
});

$cli->choice('stdin', {
  argument => 'input',
});

my $choice_prompt = $cli->choice_prompt('stdin');

# "Example prompt"

choice_range

choice_range(string $name) (string)

The choice_range method returns the range configuration value for the argument corresponding to the named choice.

Since 4.15

choice_range example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $choice_range = $cli->choice_range;

# ""
choice_range example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  range => '0:',
  type => 'string',
});

$cli->choice('stdin', {
  argument => 'input',
});

my $choice_range = $cli->choice_range('stdin');

# "0:"

choice_required

choice_required(string $name) (boolean)

The choice_required method returns the required configuration value for the argument corresponding to the named choice.

Since 4.15

choice_required example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $choice_required = $cli->choice_required;

# false
choice_required example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  required => true,
  type => 'string',
});

$cli->choice('stdin', {
  argument => 'input',
});

my $choice_required = $cli->choice_required('stdin');

# true

choice_type

choice_type(string $name) (string)

The choice_type method returns the type configuration value for the argument corresponding to the named choice.

Since 4.15

choice_type example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $choice_type = $cli->choice_type;

# ""
choice_type example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  type => 'string',
});

$cli->choice('stdin', {
  argument => 'input',
});

my $choice_type = $cli->choice_type('stdin');

# "string"

choice_validate

choice_validate(string $name) (within[arrayref, Venus::Validate])

The choice_validate method returns a Venus::Validate object for each value returned by "choice_value" for the named choice. Returns a list in list context.

Since 4.15

choice_validate example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $choice_validate = $cli->choice_validate;

# []
choice_validate example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  multiples => true,
  range => '0',
  type => 'string',
});

$cli->choice('stdin', {
  argument => 'input',
});

my $choice_validate = $cli->choice_validate('stdin');

# [bless(..., "Venus::Validate")]
choice_validate example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  multiples => false,
  range => '0',
  type => 'string',
});

$cli->choice('stdin', {
  argument => 'input',
});

my $choice_validate = $cli->choice_validate('stdin');

# bless(..., "Venus::Validate")
choice_validate example 4
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  multiples => true,
  range => '0:',
  type => 'string',
});

$cli->choice('stdin', {
  argument => 'input',
});

$cli->parse('hello', 'world');

my $choice_validate = $cli->choice_validate('stdin');

# [bless(..., "Venus::Validate"), bless(..., "Venus::Validate")]

choice_value

choice_value(string $name) (any)

The choice_value method returns the parsed choice value for the named choice.

Since 4.15

choice_value example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $choice_value = $cli->choice_value;

# undef
choice_value example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  multiples => false,
  range => '0:',
  type => 'string',
});

$cli->choice('stdin', {
  argument => 'input',
});

$cli->parse('hello', 'world');

my $choice_value = $cli->choice_value('stdin');

# "hello"
choice_value example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  multiples => true,
  range => '0:',
  type => 'string',
});

$cli->choice('stdin', {
  argument => 'input',
});

$cli->parse('hello', 'world');

my $choice_value = $cli->choice_value('stdin');

# ["hello", "world"]

choice_wants

choice_wants(string $name) (string)

The choice_wants method returns the wants configuration value for the argument corresponding to the named choice.

Since 4.15

choice_wants example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $choice_wants = $cli->choice_wants;

# ""
choice_wants example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  wants => 'string',
});

$cli->choice('stdin', {
  argument => 'input',
});

my $choice_wants = $cli->choice_wants('stdin');

# "string"

command

command(string $argument, string | arrayref $choice, string | coderef $handler) (maybe[hashref])

The command method creates and associates an argument, choice, and route. It takes an argument name, a choice name (string or arrayref of parts), and a handler (method name or coderef). The method returns the route configuration for the command.

Since 4.15

command example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $command = $cli->command('command', ['user', 'create'], 'handle_user_create');

# {
#   name => 'user create',
#   label => undef,
#   help => undef,
#   argument => 'command',
#   choice => 'user create',
#   handler => 'handle_user_create',
#   range => ':1',
#   index => 0,
# }
command example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $command = $cli->command('command', 'user create', 'handle_user_create');

# {
#   name => 'user create',
#   label => undef,
#   help => undef,
#   argument => 'command',
#   choice => 'user create',
#   handler => 'handle_user_create',
#   range => ':1',
#   index => 0,
# }
command example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $command = $cli->command('command', ['user'], 'handle_user');

# {
#   name => 'user',
#   label => undef,
#   help => undef,
#   argument => 'command',
#   choice => 'user',
#   handler => 'handle_user',
#   range => ':0',
#   index => 0,
# }
command example 4
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->command('command', ['user', 'create'], 'handle_user_create');
$cli->command('command', ['user', 'delete'], 'handle_user_delete');

my $argument = $cli->argument('command');

# {
#   name => 'command',
#   ...
#   range => ':1',
# }

dispatch

dispatch(any @args) (any)

The dispatch method parses CLI arguments, matches them against registered routes, and invokes the appropriate handler. If the handler is a coderef, it is called with the CLI instance, "assigned_arguments", and "assigned_options". If the handler is a local method name, it is called with </assigned_arguments>, and "assigned_options". If the handler is a package name, the package is loaded and instantiated. If the package is a Venus::Task, its "handle" in Venus::Task method is called. If the package is a Venus::Cli, its "dispatch" method is called. When dispatching to a package, only the relevant portion of the command line arguments (after the matched command) is passed.

Since 4.15

dispatch example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $dispatch = $cli->dispatch;

# undef
dispatch example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->command('command', ['user', 'create'], 'handle_user_create');

my $dispatch = $cli->dispatch('user', 'create');

# undef (no handler method exists)
dispatch example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $handler_called = 0;
my $handler_args;

$cli->command('command', ['user', 'create'], sub {
  my ($self, $args, $opts) = @_;
  $handler_called = 1;
  $handler_args = [$args, $opts];
  return 'handler result';
});

my $dispatch = $cli->dispatch('user', 'create');

# "handler result"
dispatch example 4
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->command('command', ['user', 'create'], sub {'user_create'});
$cli->command('command', ['user', 'delete'], sub {'user_delete'});
$cli->command('command', ['user'], sub {'user'});

my $dispatch = $cli->dispatch('user', 'create');

# "user_create"
dispatch example 5
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->command('command', ['user', 'create'], sub {'user_create'});
$cli->command('command', ['user', 'delete'], sub {'user_delete'});
$cli->command('command', ['user'], sub {'user'});

my $dispatch = $cli->dispatch('user');

# "user"
dispatch example 6
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->command('command', ['user', 'create'], sub {'user_create'});
$cli->command('command', ['user', 'delete'], sub {'user_delete'});
$cli->command('command', ['user'], sub {'user'});

my $dispatch = $cli->dispatch('user', 'delete');

# "user_delete"
dispatch example 7
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('verbose', {
  type => 'boolean',
  alias => 'v',
});

$cli->command('command', ['user', 'create'], sub {
  my ($self, $args, $opts) = @_;
  return $opts->{verbose} ? 'verbose' : 'quiet';
});

my $dispatch = $cli->dispatch('user', 'create', '--verbose');

# "verbose"
dispatch example 8
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->command('command', ['unknown'], sub {'unknown'});

my $dispatch = $cli->dispatch('other');

# undef (no matching route)

exit

exit(number $expr, string | coderef $code, any @args) (any)

The exit method terminates the program with a specified exit code. If no exit code is provided, it defaults to 0, indicating a successful exit. This method can be used to end the program explicitly, either after a specific task is completed or when an error occurs that requires halting execution. This method can dispatch to another method or callback before exiting.

Since 4.15

exit example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->exit;

# 0
exit example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->exit(1);

# 1
exit example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->exit(5, sub{
  $cli->{dispatched} = 1;
});

# 5

fail

fail(string | coderef $code, any @args) (any)

The fail method terminates the program with a the exit code 1, indicating a failure on exit. This method can be used to end the program explicitly, either after a specific task is completed or when an error occurs that requires halting execution. This method can dispatch to another method or callback before exiting.

Since 4.15

fail example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->fail;

# 1
fail example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->fail(sub{
  $cli->{dispatched} = 1;
});

# 1

float

float(string $method, any @args) (any)

The float method is a configuration dispatcher and shorthand for {'type', 'float'}. It returns the data or dispatches to the next configuration dispatcher based on the name provided and merges the configurations produced.

Since 4.15

float example 1
# given: synopsis

package main;

my $float = $cli->float;

# {type => 'float'}
float example 2
# given: synopsis

package main;

my $float = $cli->float(undef, {required => true});

# {type => 'float', required => true}
float example 3
# given: synopsis

package main;

my $float = $cli->float('option', 'example');

# {
#   name => 'example',
#   label => undef,
#   help => 'Expects a float value',
#   default => undef,
#   aliases => [],
#   multiples => 0,
#   prompt => undef,
#   range => undef,
#   required => 1,
#   type => 'float',
#   index => 0,
#   wants => 'float',
# }

has_input

has_input() (boolean)

The has_input method returns true if input arguments and/or options are found, and otherwise returns false.

Since 4.15

has_input example 1
# given: synopsis

package main;

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

my $has_input = $cli->has_input;

# false
has_input example 2
# given: synopsis

package main;

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->parse('--input', 'stdin');

my $has_input = $cli->has_input;

# true

has_input_arguments

has_input_arguments() (boolean)

The has_input_arguments method returns true if input arguments are found, and otherwise returns false.

Since 4.15

has_input_arguments example 1
# given: synopsis

package main;

$cli->argument('args', {
  range => '0:',
  type => 'string',
});

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

my $has_input_arguments = $cli->has_input_arguments;

# false
has_input_arguments example 2
# given: synopsis

package main;

$cli->argument('args', {
  range => '0:',
  type => 'string',
});

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->parse('example');

my $has_input_arguments = $cli->has_input_arguments;

# true

has_input_options

has_input_options() (boolean)

The has_input_options method returns true if input options are found, and otherwise returns false.

Since 4.15

has_input_options example 1
# given: synopsis

package main;

$cli->argument('args', {
  range => '0:',
  type => 'string',
});

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

my $has_input_options = $cli->has_input_options;

# false
has_input_options example 2
# given: synopsis

package main;

$cli->argument('args', {
  range => '0:',
  type => 'string',
});

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->parse('--input', 'stdout');

my $has_input_options = $cli->has_input_options;

# true

has_output

has_output() (boolean)

The has_output method returns true if output events are found, and otherwise returns false.

Since 4.15

has_output example 1
# given: synopsis

package main;

$cli->argument('args', {
  range => '0:',
  type => 'string',
});

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

my $has_output = $cli->has_output;

# false
has_output example 2
# given: synopsis

package main;

$cli->argument('args', {
  range => '0:',
  type => 'string',
});

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->log_info('example output');

my $has_output = $cli->has_output;

# true

has_output_debug_events

has_output_debug_events() (boolean)

The has_output_debug_events method returns true if debug output events are found, and otherwise returns false.

Since 4.15

has_output_debug_events example 1
# given: synopsis

package main;

$cli->argument('args', {
  range => '0:',
  type => 'string',
});

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->log_info('example output');

my $has_output_debug_events = $cli->has_output_debug_events;

# false
has_output_debug_events example 2
# given: synopsis

package main;

$cli->argument('args', {
  range => '0:',
  type => 'string',
});

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->log_debug('example output');

my $has_output_debug_events = $cli->has_output_debug_events;

# true

has_output_error_events

has_output_error_events() (boolean)

The has_output_error_events method returns true if error output events are found, and otherwise returns false.

Since 4.15

has_output_error_events example 1
# given: synopsis

package main;

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->log_info('example output');

my $has_output_error_events = $cli->has_output_error_events;

# false
has_output_error_events example 2
# given: synopsis

package main;

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->log_error('example output');

my $has_output_error_events = $cli->has_output_error_events;

# true

has_output_fatal_events

has_output_fatal_events() (boolean)

The has_output_fatal_events method returns true if fatal output events are found, and otherwise returns false.

Since 4.15

has_output_fatal_events example 1
# given: synopsis

package main;

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->log_info('example output');

my $has_output_fatal_events = $cli->has_output_fatal_events;

# false
has_output_fatal_events example 2
# given: synopsis

package main;

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->log_fatal('example output');

my $has_output_fatal_events = $cli->has_output_fatal_events;

# true

has_output_info_events

has_output_info_events() (boolean)

The has_output_info_events method returns true if info output events are found, and otherwise returns false.

Since 4.15

has_output_info_events example 1
# given: synopsis

package main;

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->log_info('example output');

my $has_output_info_events = $cli->has_output_info_events;

# true
has_output_info_events example 2
# given: synopsis

package main;

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->log_error('example output');

my $has_output_info_events = $cli->has_output_info_events;

# false

has_output_trace_events

has_output_trace_events() (boolean)

The has_output_trace_events method returns true if trace output events are found, and otherwise returns false.

Since 4.15

has_output_trace_events example 1
# given: synopsis

package main;

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->log_info('example output');

my $has_output_trace_events = $cli->has_output_trace_events;

# false
has_output_trace_events example 2
# given: synopsis

package main;

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->log_trace('example output');

my $has_output_trace_events = $cli->has_output_trace_events;

# true

has_output_warn_events

has_output_warn_events() (boolean)

The has_output_warn_events method returns true if warn output events are found, and otherwise returns false.

Since 4.15

has_output_warn_events example 1
# given: synopsis

package main;

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->log_info('example output');

my $has_output_warn_events = $cli->has_output_warn_events;

# false
has_output_warn_events example 2
# given: synopsis

package main;

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->log_warn('example output');

my $has_output_warn_events = $cli->has_output_warn_events;

# true

help

help() (Venus::Cli)

The help method uses "log_info" method to output CLI usage/help text.

Since 4.15

help example 1
# given: synopsis

package main;

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

my $help = $cli->help;

# bless(..., "Venus::Cli")

input

input() (hashref)

The input method returns input arguments in scalar context, and returns arguments and options in list context. Arguments and options are returned as hashrefs.

Since 4.15

input example 1
# given: synopsis

package main;

$cli->argument('args', {
  range => '0:',
  type => 'string',
});

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

my $input = $cli->input;

# {args => undef}
input example 2
# given: synopsis

package main;

$cli->argument('args', {
  range => '0:',
  multiples => 1,
  type => 'string',
});

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->parse('arg1', 'arg2');

my $input = $cli->input;

# {args => ['arg1', 'arg2']}

input_argument_count

input_argument_count() (number)

The input_argument_count method returns the number of arguments provided to the CLI.

Since 4.15

input_argument_count example 1
# given: synopsis

package main;

$cli->argument('args', {
  range => '0:',
  multiples => 1,
  type => 'string',
});

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

my $input_argument_count = $cli->input_argument_count;

# 1
input_argument_count example 2
# given: synopsis

package main;

$cli->argument('args', {
  range => '0:',
  multiples => 1,
  type => 'string',
});

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->parse('arg1', 'arg2');

my $input_argument_count = $cli->input_argument_count;

# 1

input_argument_list

input_argument_list() (arrayref)

The input_argument_list method returns the list of argument names as an arrayref in scalar context, and as a list in list context.

Since 4.15

input_argument_list example 1
# given: synopsis

package main;

$cli->argument('args', {
  range => '0:',
  multiples => 1,
  type => 'string',
});

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

my $input_argument_list = $cli->input_argument_list;

# ['args']
input_argument_list example 2
# given: synopsis

package main;

$cli->argument('args', {
  range => '0:',
  multiples => 1,
  type => 'string',
});

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

my @input_argument_list = $cli->input_argument_list;

# ('args')

input_arguments

input_arguments() (hashref)

The input_arguments method returns the list of argument names and values as a hashref.

Since 4.15

input_arguments example 1
# given: synopsis

package main;

$cli->argument('args', {
  range => '0:',
  multiples => 1,
  type => 'string',
});

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

my $input_arguments = $cli->input_arguments;

# {args => []}
input_arguments example 2
# given: synopsis

package main;

$cli->argument('args', {
  range => '0:',
  multiples => 1,
  type => 'string',
});

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->parse('arg1', 'arg2');

my $input_arguments = $cli->input_arguments;

# {args => ['arg1', 'arg2']}

input_arguments_defined

input_arguments_defined() (hashref)

The input_arguments_defined method returns the list of argument names and values as a hashref, excluding undefined and empty arrayref values.

Since 4.15

input_arguments_defined example 1
# given: synopsis

package main;

$cli->argument('args', {
  range => '0:',
  multiples => 1,
  type => 'string',
});

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

my $input_arguments_defined = $cli->input_arguments_defined;

# {}
input_arguments_defined example 2
# given: synopsis

package main;

$cli->argument('args', {
  range => '0:',
  multiples => 1,
  type => 'string',
});

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->parse('arg1', 'arg2');

my $input_arguments_defined = $cli->input_arguments_defined;

# {args => ['arg1', 'arg2']}

input_arguments_defined_count

input_arguments_defined_count() (number)

The input_arguments_defined_count method returns the number of arguments found using "input_arguments_defined".

Since 4.15

input_arguments_defined_count example 1
# given: synopsis

package main;

$cli->argument('args', {
  range => '0:',
  multiples => 1,
  type => 'string',
});

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

my $input_arguments_defined_count = $cli->input_arguments_defined_count;

# 0
input_arguments_defined_count example 2
# given: synopsis

package main;

$cli->argument('args', {
  range => '0:',
  multiples => 1,
  type => 'string',
});

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->parse('arg1', 'arg2');

my $input_arguments_defined_count = $cli->input_arguments_defined_count;

# 1

input_arguments_defined_list

input_arguments_defined_list() (arrayref)

The input_arguments_defined_list method returns the list of argument names found, using "input_arguments_defined", as an arrayref in scalar context, and as a list in list context.

Since 4.15

input_arguments_defined_list example 1
# given: synopsis

package main;

$cli->argument('args', {
  range => '0:',
  multiples => 1,
  type => 'string',
});

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

my $input_arguments_defined_list = $cli->input_arguments_defined_list;

# []
input_arguments_defined_list example 2
# given: synopsis

package main;

$cli->argument('args', {
  range => '0:',
  multiples => 1,
  type => 'string',
});

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->parse('arg1', 'arg2');

my $input_arguments_defined_list = $cli->input_arguments_defined_list;

# ['args']

input_option_count

input_option_count() (number)

The input_option_count method returns the number of options provided to the CLI.

Since 4.15

input_option_count example 1
# given: synopsis

package main;

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

my $input_option_count = $cli->input_option_count;

# 2
input_option_count example 2
# given: synopsis

package main;

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->parse('--input', 'stdin');

my $input_option_count = $cli->input_option_count;

# 2

input_option_list

input_option_list() (arrayref)

The input_option_list method returns the list of option names as an arrayref in scalar context, and as a list in list context.

Since 4.15

input_option_list example 1
# given: synopsis

package main;

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

my $input_option_list = $cli->input_option_list;

# ['input', 'output']
input_option_list example 2
# given: synopsis

package main;

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->parse('--input', 'stdin', '--output', 'stdout');

my $input_option_list = $cli->input_option_list;

# ['input', 'output']

input_options

input_options() (hashref)

The input_options method returns the list of option names and values as a hashref.

Since 4.15

input_options example 1
# given: synopsis

package main;

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

my $input_options = $cli->input_options;

# {input => undef, output => undef}
input_options example 2
# given: synopsis

package main;

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->parse('--input', 'stdin', '--output', 'stdout');

my $input_options = $cli->input_options;

# {input => undef, output => undef}

input_options_defined

input_options_defined() (hashref)

The input_options_defined method returns the list of option names and values as a hashref, excluding undefined and empty arrayref values.

Since 4.15

input_options_defined example 1
# given: synopsis

package main;

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

my $input_options_defined = $cli->input_options_defined;

# {}
input_options_defined example 2
# given: synopsis

package main;

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->parse('--input', 'stdin', '--output', 'stdout');

my $input_options_defined = $cli->input_options_defined;

# {input => 'stdin', output => 'stdout'}

input_options_defined_count

input_options_defined_count() (number)

The input_options_defined_count method returns the number of options found using "input_options_defined".

Since 4.15

input_options_defined_count example 1
# given: synopsis

package main;

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

my $input_options_defined_count = $cli->input_options_defined_count;

# 0
input_options_defined_count example 2
# given: synopsis

package main;

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->parse('--input', 'stdin', '--output', 'stdout');

my $input_options_defined_count = $cli->input_options_defined_count;

# 2

input_options_defined_list

input_options_defined_list() (arrayref)

The input_options_defined_list method returns the list of option names found, using "input_options_defined", as an arrayref in scalar context, and as a list in list context.

Since 4.15

input_options_defined_list example 1
# given: synopsis

package main;

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

my $input_options_defined_list = $cli->input_options_defined_list;

# []
input_options_defined_list example 2
# given: synopsis

package main;

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->parse('--input', 'stdin', '--output', 'stdout');

my $input_options_defined_list = $cli->input_options_defined_list;

# ['input', 'output']
input_options_defined_list example 3
# given: synopsis

package main;

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->parse('--output', 'stdout');

my $input_options_defined_list = $cli->input_options_defined_list;

# ['output']

lines

lines(string $text, number $length, number $indent) (string)

The lines method takes a string of text, a maximum character length for each line, and an optional number of spaces to use for indentation (defaulting to 0). It returns the text formatted as a string where each line wraps at the specified length and is indented with the given number of spaces. The default lenght is 80.

Since 4.15

lines example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $message = join(' ',
  'This is an example of a long line of text that needs',
  'to be wrapped and formatted.'
);

my $string = $cli->lines($message, 40, 2);

# "  This is an example of a long line of
#   text that needs to be wrapped and
#   formatted."

log

log() (Venus::Log)

The log method returns a Venus::Log object passing "log_handler" and "log_level" to its constructor.

Since 4.15

log example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $log = $cli->log;

# bless(..., "Venus::Log")

log_debug

log_debug(any @args) (Venus::Log)

The log_debug method dispatches to the debug method on the object returned by "log".

Since 4.15

log_debug example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $log_debug = $cli->log_debug('Example debug');

# bless(..., "Venus::Log")

log_error

log_error(any @args) (Venus::Log)

The log_error method dispatches to the error method on the object returned by "log".

Since 4.15

log_error example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $log_error = $cli->log_error('Example error');

# bless(..., "Venus::Log")

log_events

log_events() (arrayref)

The log_events method returns the log messages collected by the default "log_handler".

Since 4.15

log_events example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->log_debug('Example debug');

$cli->log_error('Example error');

my $log_events = $cli->log_events;

# [['debug', 'Example debug'], ['debug', 'Example error']]

log_fatal

log_fatal(any @args) (Venus::Log)

The log_fatal method dispatches to the fatal method on the object returned by "log".

Since 4.15

log_fatal example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $log_fatal = $cli->log_fatal('Example fatal');

# bless(..., "Venus::Log")

log_flush

log_flush(string | coderef $code) (Venus::Cli)

The log_flush method dispatches to the method or callback provided for each "log event", then purges all log events.

Since 4.15

log_flush example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->log_debug('Example debug 1');

$cli->log_debug('Example debug 2');

my $log_flush = $cli->log_flush(sub{
  push @{$cli->{flushed} ||= []}, $_;
});

# bless(..., "Venus::Cli")
log_flush example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->log_debug('Example debug 1');

$cli->log_debug('Example debug 2');

my $log_flush = $cli->log_flush(sub{
  my ($self, $event) = @_;
  push @{$cli->{flushed} ||= []}, $event;
});

# bless(..., "Venus::Cli")

log_handler

log_handler() (coderef)

The log_handler method is passed to the Venus::Log constructor in "log" and by default handles log events by recording them to be "flushed" later.

Since 4.15

log_handler example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $log_handler = $cli->log_handler;

# sub{...}

log_info

log_info(any @args) (Venus::Log)

The log_info method dispatches to the info method on the object returned by "log".

Since 4.15

log_info example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $log_info = $cli->log_info('Example info');

# bless(..., "Venus::Log")

log_level

log_level() (string)

The log_level method is passed to the Venus::Log constructor in "log" and by default specifies a log-level of debug.

Since 4.15

log_level example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $log_level = $cli->log_level;

# "trace"

log_trace

log_trace(any @args) (Venus::Log)

The log_trace method dispatches to the trace method on the object returned by "log".

Since 4.15

log_trace example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $log_trace = $cli->log_trace('Example trace');

# bless(..., "Venus::Log")

log_warn

log_warn(any @args) (Venus::Log)

The log_warn method dispatches to the warn method on the object returned by "log".

Since 4.15

log_warn example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $log_warn = $cli->log_warn('Example warn');

# bless(..., "Venus::Log")

multiple

multiple(string $method, any @args) (any)

The multiple method is a configuration dispatcher and shorthand for {'multiples', true}. It returns the data or dispatches to the next configuration dispatcher based on the name provided and merges the configurations produced.

Since 4.15

multiple example 1
# given: synopsis

package main;

my $multiple = $cli->multiple;

# {multiples => true}
multiple example 2
# given: synopsis

package main;

my $multiple = $cli->multiple(undef, {required => true});

# {multiples => true, required => true}
multiple example 3
# given: synopsis

package main;

my $multiple = $cli->multiple('option', 'example');

# {
#   name => 'example',
#   label => undef,
#   help => 'Expects a string value',
#   default => undef,
#   aliases => [],
#   multiples => 1,
#   prompt => undef,
#   range => undef,
#   required => 1,
#   type => 'string',
#   index => 0,
#   wants => 'string',
# }

new

new(any @args) (Venus::Cli)

The new method constructs an instance of the package.

Since 4.15

new example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new('mycli');

# bless(..., "Venus::Cli")

# $cli->name;

# "mycli"
new example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

# bless(..., "Venus::Cli")

# $cli->name;

# "mycli"

no_input

no_input() (boolean)

The no_input method returns true if no arguments or options are provided to the CLI, and false otherwise.

Since 4.15

no_input example 1
# given: synopsis

package main;

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

my $no_input = $cli->no_input;

# true
no_input example 2
# given: synopsis

package main;

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->parse('--input', 'stdin', '--output', 'stdout');

my $no_input = $cli->no_input;

# false

no_input_arguments

no_input_arguments() (boolean)

The no_input_arguments method returns true if no arguments are provided to the CLI, and false otherwise.

Since 4.15

no_input_arguments example 1
# given: synopsis

package main;

$cli->argument('args', {
  range => '0:',
  multiples => 1,
  type => 'string',
});

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

my $no_input_arguments = $cli->no_input_arguments;

# true
no_input_arguments example 2
# given: synopsis

package main;

$cli->argument('args', {
  range => '0:',
  multiples => 1,
  type => 'string',
});

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->parse('arg1', 'arg2', '--output', 'stdout');

my $no_input_arguments = $cli->no_input_arguments;

# false

no_input_options

no_input_options() (boolean)

The no_input_options method returns true if no options are provided to the CLI, and false otherwise.

Since 4.15

no_input_options example 1
# given: synopsis

package main;

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

my $no_input_options = $cli->no_input_options;

# true
no_input_options example 2
# given: synopsis

package main;

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->parse('--input', 'stdin');

my $no_input_options = $cli->no_input_options;

# false

no_output

no_output() (boolean)

The no_output method returns true if no output events are found, and false otherwise.

Since 4.15

no_output example 1
# given: synopsis

package main;

my $no_output = $cli->no_output;

# true
no_output example 2
# given: synopsis

package main;

$cli->log_info('example output');

my $no_output = $cli->no_output;

# false

no_output_debug_events

no_output_debug_events() (boolean)

The no_output_debug_events method returns true if no debug output events are found, and false otherwise.

Since 4.15

no_output_debug_events example 1
# given: synopsis

package main;

$cli->log_info('example output');

my $no_output_debug_events = $cli->no_output_debug_events;

# true
no_output_debug_events example 2
# given: synopsis

package main;

$cli->log_debug('example output');

my $no_output_debug_events = $cli->no_output_debug_events;

# false

no_output_error_events

no_output_error_events() (boolean)

The no_output_error_events method returns true if no error output events are found, and false otherwise.

Since 4.15

no_output_error_events example 1
# given: synopsis

package main;

$cli->log_info('example output');

my $no_output_error_events = $cli->no_output_error_events;

# true
no_output_error_events example 2
# given: synopsis

package main;

$cli->log_error('example output');

my $no_output_error_events = $cli->no_output_error_events;

# false

no_output_fatal_events

no_output_fatal_events() (boolean)

The no_output_fatal_events method returns true if no fatal output events are found, and false otherwise.

Since 4.15

no_output_fatal_events example 1
# given: synopsis

package main;

$cli->log_info('example output');

my $no_output_fatal_events = $cli->no_output_fatal_events;

# true
no_output_fatal_events example 2
# given: synopsis

package main;

$cli->log_fatal('example output');

my $no_output_fatal_events = $cli->no_output_fatal_events;

# false

no_output_info_events

no_output_info_events() (boolean)

The no_output_info_events method returns true if no info output events are found, and false otherwise.

Since 4.15

no_output_info_events example 1
# given: synopsis

package main;

$cli->log_info('example output');

my $no_output_info_events = $cli->no_output_info_events;

# false
no_output_info_events example 2
# given: synopsis

package main;

$cli->log_error('example output');

my $no_output_info_events = $cli->no_output_info_events;

# true

no_output_trace_events

no_output_trace_events() (boolean)

The no_output_trace_events method returns true if no trace output events are found, and false otherwise.

Since 4.15

no_output_trace_events example 1
# given: synopsis

package main;

$cli->log_info('example output');

my $no_output_trace_events = $cli->no_output_trace_events;

# true
no_output_trace_events example 2
# given: synopsis

package main;

$cli->log_trace('example output');

my $no_output_trace_events = $cli->no_output_trace_events;

# false

no_output_warn_events

no_output_warn_events() (boolean)

The no_output_warn_events method returns true if no warn output events are found, and false otherwise.

Since 4.15

no_output_warn_events example 1
# given: synopsis

package main;

$cli->log_info('example output');

my $no_output_warn_events = $cli->no_output_warn_events;

# true
no_output_warn_events example 2
# given: synopsis

package main;

$cli->log_warn('example output');

my $no_output_warn_events = $cli->no_output_warn_events;

# false

number

number(string $method, any @args) (any)

The number method is a configuration dispatcher and shorthand for {'type', 'number'}. It returns the data or dispatches to the next configuration dispatcher based on the name provided and merges the configurations produced.

Since 4.15

number example 1
# given: synopsis

package main;

my $number = $cli->number;

# {type => 'number'}
number example 2
# given: synopsis

package main;

my $number = $cli->number(undef, {required => true});

# {type => 'number', required => true}
number example 3
# given: synopsis

package main;

my $number = $cli->number('option', 'example');

# {
#   name => 'example',
#   label => undef,
#   help => 'Expects a number value',
#   default => undef,
#   aliases => [],
#   multiples => 0,
#   prompt => undef,
#   range => undef,
#   required => 1,
#   type => 'number',
#   index => 0,
#   wants => 'number',
# }

okay

okay(string | coderef $code, any @args) (any)

The okay method terminates the program with a the exit code 0, indicating a successful exit. This method can be used to end the program explicitly, either after a specific task is completed or when an error occurs that requires halting execution. This method can dispatch to another method or callback before exiting.

Since 4.15

okay example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->okay;

# 0
okay example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->okay(sub{
  $cli->{dispatched} = 1;
});

# 0

option

option(string $name, hashref $data) (maybe[hashref])

The option method registers and returns the configuration for the option specified. The method takes a name (option name) and a hashref of configuration values. The possible configuration values are as follows:

  • The name key holds the name of the option.

  • The label key holds the name of the option as it should be displayed in the CLI help text.

  • The help key holds the help text specific to this option.

  • The default key holds the default value that should used if no value for this option is provided to the CLI.

  • The aliases (or alias) key holds the arrayref of aliases that can be provided to the CLI to specify a value (or values) for this option.

  • The multiples key denotes whether this option can be used more than once, to collect multiple values, and holds a 1 if multiples are allowed and a 0 otherwise.

  • The prompt key holds the question or statement that should be presented to the user of the CLI if no value has been provided for this option and no default value has been set.

  • The range key holds a two-value arrayref where the first value is the starting index and the second value is the ending index. These values are used to select values from the parsed arguments array as the value(s) for this argument. This value is ignored if the multiples key is set to 0.

  • The required key denotes whether this option is required or not, and holds a 1 if required and a 0 otherwise.

  • The type key holds the data type of the option expected. Valid values are "number", "string", "float", "boolean", or "yesno". Note: Valid boolean values are 1, 0, "true", and "false".

  • The wants key holds the text to be used as a value being assigned to the option in the usage text. This value defaults to the type specified, or "string".

Since 4.15

option example 1
# given: synopsis

package main;

my $option = $cli->option('name', {
  label => 'Name',
  help => 'The name of the user',
  default => 'Unknown',
  required => 1,
  type => 'string'
});

# {
#   name => 'name',
#   label => 'Name',
#   help => 'The name of the user',
#   default => 'Unknown',
#   aliases => [],
#   multiples => 0,
#   prompt => undef,
#   range => undef,
#   required => 1,
#   type => 'string',
#   index => 0,
#   wants => 'string',
# }

option_aliases

option_aliases(string $name) (arrayref)

The option_aliases method returns the aliases configuration value for the named option.

Since 4.15

option_aliases example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $option_aliases = $cli->option_aliases;

# []
option_aliases example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  alias => 'i',
  type => 'string',
});

my $option_aliases = $cli->option_aliases('input');

# ['i']
option_aliases example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  aliases => 'i',
  type => 'string',
});

my $option_aliases = $cli->option_aliases('input');

# ['i']
option_aliases example 4
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  aliases => ['i'],
  type => 'string',
});

my $option_aliases = $cli->option_aliases('input');

# ['i']

option_count

option_count() (number)

The option_count method returns the count of registered options.

Since 4.15

option_count example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $option_count = $cli->option_count;

# 0
option_count example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

my $option_count = $cli->option_count;

# 2

option_default

option_default(string $name) (string)

The option_default method returns the default configuration value for the named option.

Since 4.15

option_default example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $option_default = $cli->option_default;

# ""
option_default example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  default => 'stdin',
});

my $option_default = $cli->option_default('input');

# "stdin"

option_errors

option_errors(string $name) (within[arrayref, Venus::Validate])

The option_errors method returns a list of "issues", if any, for each value returned by "option_value" for the named option. Returns a list in list context.

Since 4.15

option_errors example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $option_errors = $cli->option_errors;

# []
option_errors example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  type => 'string',
});

$cli->parse('--input hello');

my $option_errors = $cli->option_errors('input');

# []
option_errors example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  default => 'hello',
  type => 'number',
});

$cli->parse('--input hello');

my $option_errors = $cli->option_errors('input');

# [['type', ['number']]]

option_help

option_help(string $name) (string)

The option_help method returns the help configuration value for the named option.

Since 4.15

option_help example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $option_help = $cli->option_help;

# ""
option_help example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  help => 'Example help text',
});

my $option_help = $cli->option_help('input');

# "Example help text"

option_label

option_label(string $name) (string)

The option_label method returns the label configuration value for the named option.

Since 4.15

option_label example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $option_label = $cli->option_label;

# ""
option_label example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  label => 'Input',
});

my $option_label = $cli->option_label('input');

# "Input"

option_list

option_list(string $name) (within[arrayref, hashref])

The option_list method returns a list of registered option configurations. Returns a list in list context.

Since 4.15

option_list example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $option_list = $cli->option_list;

# []
option_list example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  type => 'string',
});

my $option_list = $cli->option_list;

# [{
#   name => 'input',
#   label => undef,
#   help => 'Expects a string value',
#   aliases => [],
#   default => undef,
#   multiples => 0,
#   prompt => undef,
#   range => undef,
#   required => false,
#   type => 'string',
#   index => 0,
#   wants => 'string',
# }]

option_multiples

option_multiples(string $name) (boolean)

The option_multiples method returns the multiples configuration value for the named option.

Since 4.15

option_multiples example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $option_multiples = $cli->option_multiples;

# false
option_multiples example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  multiples => true,
});

my $option_multiples = $cli->option_multiples('input');

# true

option_name

option_name(string $name) (string)

The option_name method returns the name configuration value for the named option.

Since 4.15

option_name example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $option_name = $cli->option_name;

# ""
option_name example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  name => 'INPUT',
});

my $option_name = $cli->option_name('input');

# ""
option_name example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  name => 'INPUT',
});

my $option_name = $cli->option_name('INPUT');

# "INPUT"

option_names

option_names(string $name) (within[arrayref, string])

The option_names method returns the names (keys) of registered options in the order declared. Returns a list in list context.

Since 4.15

option_names example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $option_names = $cli->option_names;

# []
option_names example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

my $option_names = $cli->option_names;

# ['input', 'output']
option_names example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('output', {
  type => 'string',
});

$cli->option('input', {
  type => 'string',
});

my $option_names = $cli->option_names;

# ['output', 'input']

option_prompt

option_prompt(string $name) (string)

The option_prompt method returns the prompt configuration value for the named option.

Since 4.15

option_prompt example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $option_prompt = $cli->option_prompt;

# ""
option_prompt example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  prompt => 'Example prompt',
});

my $option_prompt = $cli->option_prompt('input');

# "Example prompt"

option_range

option_range(string $name) (string)

The option_range method returns the range configuration value for the named option.

Since 4.15

option_range example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $option_range = $cli->option_range;

# ""
option_range example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  range => '0',
});

my $option_range = $cli->option_range('input');

# "0"
option_range example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  range => '0:5',
});

my $option_range = $cli->option_range('input');

# "0:5"

option_required

option_required(string $name) (boolean)

The option_required method returns the required configuration value for the named option.

Since 4.15

option_required example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $option_required = $cli->option_required;

# false
option_required example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  required => true,
});

my $option_required = $cli->option_required('input');

# true

option_type

option_type(string $name) (string)

The option_type method returns the type configuration value for the named option. Valid values are as follows:

  • number

  • string

  • float

  • boolean - Note: Valid boolean values are 1, 0, "true", and "false".

  • yesno

Since 4.15

option_type example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $option_type = $cli->option_type;

# ""
option_type example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  type => 'boolean',
});

my $option_type = $cli->option_type('input');

# "boolean"

option_validate

option_validate(string $name) (Venus::Validate | within[arrayref, Venus::Validate])

The option_validate method returns a Venus::Validate object for each value returned by "option_value" for the named option. Returns a list in list context.

Since 4.15

option_validate example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $option_validate = $cli->option_validate;

# []
option_validate example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  multiples => true,
  type => 'string',
});

my $option_validate = $cli->option_validate('input');

# [bless(..., "Venus::Validate")]
option_validate example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  multiples => false,
  type => 'string',
});

my $option_validate = $cli->option_validate('input');

# bless(..., "Venus::Validate")
option_validate example 4
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  multiples => true,
  type => 'string',
});

$cli->parse('--input', 'hello', '--input', 'world');

my $option_validate = $cli->option_validate('input');

# [bless(..., "Venus::Validate"), bless(..., "Venus::Validate")]

option_value

option_value(string $name) (any)

The option_value method returns the parsed option value for the named option.

Since 4.15

option_value example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $option_value = $cli->option_value;

# undef
option_value example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  multiples => false,
  type => 'string',
});

$cli->parse('--input', 'hello', '--input', 'world');

my $option_value = $cli->option_value('input');

# "world"
option_value example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  multiples => true,
  type => 'string',
});

$cli->parse('--input', 'hello', '--input', 'world');

my $option_value = $cli->option_value('input');

# ["hello", "world"]

option_wants

option_wants(string $name) (string)

The option_wants method returns the wants configuration value for the named option.

Since 4.15

option_wants example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $option_wants = $cli->option_wants;

# ""
option_wants example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  wants => 'string',
});

my $option_wants = $cli->option_wants('input');

# "string"

optional

optional(string $method, any @args) (any)

The optional method is a configuration dispatcher and shorthand for {'required', false}. It returns the data or dispatches to the next configuration dispatcher based on the name provided and merges the configurations produced.

Since 4.15

optional example 1
# given: synopsis

package main;

my $optional = $cli->optional;

# {required => false}
optional example 2
# given: synopsis

package main;

my $optional = $cli->optional(undef, {type => 'boolean'});

# {required => false, type => 'boolean'}
optional example 3
# given: synopsis

package main;

my $optional = $cli->optional('option', 'example');

# {
#   name => 'example',
#   label => undef,
#   help => 'Expects a string value',
#   default => undef,
#   aliases => [],
#   multiples => 0,
#   prompt => undef,
#   range => undef,
#   required => 0,
#   type => 'string',
#   index => 0,
#   wants => 'string',
# }

opts

opts() (Venus::Opts)

The opts method returns the list of parsed command-line options as a Venus::Opts object.

Since 4.15

opts example 1
# given: synopsis

package main;

my $opts = $cli->opts;

# bless(..., "Venus::Opts")
opts example 2
# given: synopsis

package main;

$cli->option('input', {
  type => 'string',
});

$cli->parse('--input', 'hello world');

my $opts = $cli->opts;

# bless(..., "Venus::Opts")

# $opts->input;

output

output(string $level) (any)

The output method returns the list of output events as an arrayref in scalar context, and a list in list context. The method optionally takes a log-level and if provided will only return output events for that log-level.

Since 4.15

output example 1
# given: synopsis

package main;

my $output = $cli->output;

# undef
output example 2
# given: synopsis

package main;

$cli->log_info('example output');

my $output = $cli->output;

# "example output"
output example 3
# given: synopsis

package main;

$cli->log_info('example output 1');

$cli->log_info('example output 2');

my @output = $cli->output;

# ('example output 1', 'example output 2')

output_debug_events

output_debug_events() (arrayref)

The output_debug_events method returns the list of debug output events as an arrayref in scalar context, and a list in list context.

Since 4.15

output_debug_events example 1
# given: synopsis

package main;

$cli->log_info('example output');

my $output_debug_events = $cli->output_debug_events;

# []
output_debug_events example 2
# given: synopsis

package main;

$cli->log_debug('example output');

my $output_debug_events = $cli->output_debug_events;

# ['example output']
output_debug_events example 3
# given: synopsis

package main;

$cli->log_debug('example output 1');

$cli->log_debug('example output 2');

my $output_debug_events = $cli->output_debug_events;

# ['example output 1', 'example output 2']
output_debug_events example 4
# given: synopsis

package main;

$cli->log_debug('example output 1');

$cli->log_debug('example output 2');

my @output_debug_events = $cli->output_debug_events;

# ('example output 1', 'example output 2')

output_error_events

output_error_events() (arrayref)

The output_error_events method returns the list of error output events as an arrayref in scalar context, and a list in list context.

Since 4.15

output_error_events example 1
# given: synopsis

package main;

$cli->log_info('example output');

my $output_error_events = $cli->output_error_events;

# []
output_error_events example 2
# given: synopsis

package main;

$cli->log_error('example output');

my $output_error_events = $cli->output_error_events;

# ['example output']
output_error_events example 3
# given: synopsis

package main;

$cli->log_error('example output 1');

$cli->log_error('example output 2');

my $output_error_events = $cli->output_error_events;

# ['example output 1', 'example output 2']
output_error_events example 4
# given: synopsis

package main;

$cli->log_error('example output 1');

$cli->log_error('example output 2');

my @output_error_events = $cli->output_error_events;

# ('example output 1', 'example output 2')

output_fatal_events

output_fatal_events() (arrayref)

The output_fatal_events method returns the list of fatal output events as an arrayref in scalar context, and a list in list context.

Since 4.15

output_fatal_events example 1
# given: synopsis

package main;

$cli->log_info('example output');

my $output_fatal_events = $cli->output_fatal_events;

# []
output_fatal_events example 2
# given: synopsis

package main;

$cli->log_fatal('example output');

my $output_fatal_events = $cli->output_fatal_events;

# ['example output']
output_fatal_events example 3
# given: synopsis

package main;

$cli->log_fatal('example output 1');

$cli->log_fatal('example output 2');

my $output_fatal_events = $cli->output_fatal_events;

# ['example output 1', 'example output 2']
output_fatal_events example 4
# given: synopsis

package main;

$cli->log_fatal('example output 1');

$cli->log_fatal('example output 2');

my @output_fatal_events = $cli->output_fatal_events;

# ('example output 1', 'example output 2')

output_info_events

output_info_events() (arrayref)

The output_info_events method returns the list of info output events as an arrayref in scalar context, and a list in list context.

Since 4.15

output_info_events example 1
# given: synopsis

package main;

$cli->log_warn('example output');

my $output_info_events = $cli->output_info_events;

# []
output_info_events example 2
# given: synopsis

package main;

$cli->log_info('example output');

my $output_info_events = $cli->output_info_events;

# ['example output']
output_info_events example 3
# given: synopsis

package main;

$cli->log_info('example output 1');

$cli->log_info('example output 2');

my $output_info_events = $cli->output_info_events;

# ['example output 1', 'example output 2']
output_info_events example 4
# given: synopsis

package main;

$cli->log_info('example output 1');

$cli->log_info('example output 2');

my @output_info_events = $cli->output_info_events;

# ('example output 1', 'example output 2')

output_trace_events

output_trace_events() (arrayref)

The output_trace_events method returns the list of trace output events as an arrayref in scalar context, and a list in list context.

Since 4.15

output_trace_events example 1
# given: synopsis

package main;

$cli->log_info('example output');

my $output_trace_events = $cli->output_trace_events;

# []
output_trace_events example 2
# given: synopsis

package main;

$cli->log_trace('example output');

my $output_trace_events = $cli->output_trace_events;

# ['example output']
output_trace_events example 3
# given: synopsis

package main;

$cli->log_trace('example output 1');

$cli->log_trace('example output 2');

my $output_trace_events = $cli->output_trace_events;

# ['example output 1', 'example output 2']
output_trace_events example 4
# given: synopsis

package main;

$cli->log_trace('example output 1');

$cli->log_trace('example output 2');

my @output_trace_events = $cli->output_trace_events;

# ('example output 1', 'example output 2')

output_warn_events

output_warn_events() (arrayref)

The output_warn_events method returns the list of warn output events as an arrayref in scalar context, and a list in list context.

Since 4.15

output_warn_events example 1
# given: synopsis

package main;

$cli->log_info('example output');

my $output_warn_events = $cli->output_warn_events;

# []
output_warn_events example 2
# given: synopsis

package main;

$cli->log_warn('example output');

my $output_warn_events = $cli->output_warn_events;

# ['example output']
output_warn_events example 3
# given: synopsis

package main;

$cli->log_warn('example output 1');

$cli->log_warn('example output 2');

my $output_warn_events = $cli->output_warn_events;

# ['example output 1', 'example output 2']
output_warn_events example 4
# given: synopsis

package main;

$cli->log_warn('example output 1');

$cli->log_warn('example output 2');

my @output_warn_events = $cli->output_warn_events;

# ('example output 1', 'example output 2')

parse

parse(any @args) (Venus::Cli)

The parse method accepts arbitrary input (typically strings or arrayrefs of strings) and parses out the arguments and options made available via "parsed_arguments" and "parsed_options" respectively. If no arguments are provided @ARGV is used as a default.

Since 4.15

parse example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $parse = $cli->parse;

# bless(..., "Venus::Cli")

# $cli->parsed_arguments

# []

# $result->parsed_options

# {}
parse example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $parse = $cli->parse('hello', 'world');

# bless(..., "Venus::Cli")

# $cli->parsed_arguments

# ['hello', 'world']

# $result->parsed_options

# {}
parse example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->argument('extra', {
  range => '0:',
  type => 'string',
});

my $parse = $cli->parse('--input', 'stdin', '--output', 'stdout', 'hello', 'world');

# bless(..., "Venus::Cli")

# $cli->parsed_arguments

# ['hello', 'world']

# $result->parsed_options

# {input => 'stdin', output => 'stdout'}

parsed

parsed() (arrayref | hashref)

The parsed method is shorthand for calling the "parsed_arguments" and/or "parsed_options" method directly. In scalar context this method returns "parsed_options". In list context returns "parsed_options" and "parsed_arguments" in that order.

Since 4.15

parsed example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $parsed = $cli->parsed;

# {}
parsed example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->parse('hello world');

my $parsed = $cli->parsed;

# {}
parsed example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->parse('hello', 'world');

my ($options, $arguments) = $cli->parsed;

# ({}, ['hello', 'world'])
parsed example 4
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->argument('extra', {
  range => '0:',
  type => 'string',
});

my $parse = $cli->parse('--input', 'stdin', '--output', 'stdout', 'hello world');

my $parsed = $cli->parsed;

# {input => 'stdin', output => 'stdout'}
parsed example 5
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->argument('extra', {
  range => '0:',
  type => 'string',
});

my $parse = $cli->parse('--input', 'stdin', '--output', 'stdout', 'hello', 'world');

my ($options, $arguments) = $cli->parsed;

# ({input => 'stdin', output => 'stdout'}, ['hello', 'world'])

parsed_arguments

parsed_arguments(arrayref $data) (arrayref)

The parsed_arguments method gets or sets the set of parsed arguments. This method calls "parse" if no data has been set.

Since 4.15

parsed_arguments example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->argument('extra', {
  range => '0:',
  type => 'string',
});

local @ARGV = qw(--input stdin --output stdout hello world);

my $parsed_arguments = $cli->parsed_arguments;

# ['hello', 'world']

parsed_options

parsed_options(hashref $data) (hashref)

The parsed_options method method gets or sets the set of parsed options. This method calls "parse" if no data has been set.

Since 4.15

parsed_options example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->argument('extra', {
  range => '0:',
  type => 'string',
});

local @ARGV = qw(--input stdin --output stdout hello world);

my $parsed_options = $cli->parsed_options;

# {input => 'stdin', output => 'stdout'}

pass

pass(string | coderef $code, any @args) (any)

The pass method terminates the program with a the exit code 0, indicating a successful exit. This method can be used to end the program explicitly, either after a specific task is completed or when an error occurs that requires halting execution. This method can dispatch to another method or callback before exiting.

Since 4.15

pass example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->pass;

# 0
pass example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->pass(sub{
  $cli->{dispatched} = 1;
});

# 0

reorder

reorder() (Venus::Cli)

The reorder method re-indexes the "arguments", "choices", and "options", based on the order they were declared.

Since 4.15

reorder example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  type => 'string',
  index => 1,
});

$cli->argument('output', {
  type => 'string',
  index => 3,
});

$cli->option('file', {
  type => 'string',
  index => 1,
});

$cli->option('directory', {
  type => 'string',
  index => 3,
});

$cli->choice('stdin', {
  argument => 'input',
  type => 'string',
  index => 1,
});

$cli->choice('stdout', {
  argument => 'output',
  type => 'string',
  index => 3,
});

my $reorder = $cli->reorder;

# bless(..., "Venus::Cli")

reorder_arguments

reorder_arguments() (Venus::Cli)

The reorder_arguments method re-indexes the "arguments" based on the order they were declared.

Since 4.15

reorder_arguments example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  type => 'string',
  index => 1,
});

$cli->argument('output', {
  type => 'string',
  index => 3,
});

my $reorder_arguments = $cli->reorder_arguments;

# bless(..., "Venus::Cli")

reorder_choices

reorder_choices() (Venus::Cli)

The reorder_choices method re-indexes the "choices" based on the order they were declared.

Since 4.15

reorder_choices example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  type => 'string',
  index => 1,
});

$cli->argument('output', {
  type => 'string',
  index => 3,
});

$cli->choice('stdin', {
  argument => 'input',
  type => 'string',
  index => 1,
});

$cli->choice('stdout', {
  argument => 'output',
  type => 'string',
  index => 3,
});

my $reorder_choices = $cli->reorder_choices;

# bless(..., "Venus::Cli")

reorder_options

reorder_options() (Venus::Cli)

The reorder_options method re-indexes the "options" based on the order they were declared.

Since 4.15

reorder_options example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('file', {
  type => 'string',
  index => 1,
});

$cli->option('directory', {
  type => 'string',
  index => 3,
});

my $reorder_options = $cli->reorder_options;

# bless(..., "Venus::Cli")

reorder_routes

reorder_routes() (Venus::Cli)

The reorder_routes method reorders the registered routes based on their indices. This method returns the invocant.

Since 4.15

reorder_routes example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->route('user create', {
  handler => 'handle_user_create',
  index => 1,
});

$cli->route('user delete', {
  handler => 'handle_user_delete',
  index => 0,
});

my $reorder_routes = $cli->reorder_routes;

# bless(..., "Venus::Cli")

required

required(string $method, any @args) (any)

The required method is a configuration dispatcher and shorthand for {'required', true}. It returns the data or dispatches to the next configuration dispatcher based on the name provided and merges the configurations produced.

Since 4.15

required example 1
# given: synopsis

package main;

my $required = $cli->required;

# {required => true}
required example 2
# given: synopsis

package main;

my $required = $cli->required(undef, {type => 'boolean'});

# {required => true, type => 'boolean'}
required example 3
# given: synopsis

package main;

my $required = $cli->required('option', 'example');

# {
#   name => 'example',
#   label => undef,
#   help => 'Expects a string value',
#   default => undef,
#   aliases => [],
#   multiples => 0,
#   prompt => undef,
#   range => undef,
#   required => 1,
#   type => 'string',
#   index => 0,
#   wants => 'string',
# }

reset

reset() (Venus::Cli)

The reset method clears the argument and option configurations, cached parsed values, and returns the invocant.

Since 4.15

reset example 1
# given: synopsis

package main;

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

my $reset = $cli->reset;

# bless(..., "Venus::Cli")
reset example 2
# given: synopsis

package main;

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->parse('--input', 'stdin', '--output', 'stdout');

my $reset = $cli->reset;

# bless(..., "Venus::Cli")

route

route(string $name, hashref $data) (maybe[hashref])

The route method registers and returns the configuration for the route specified. The method takes a name (route name) and a hashref of configuration values. The possible configuration values are as follows:

  • The name key holds the name of the route.

  • The label key holds the name of the route as it should be displayed in the CLI help text.

  • The help key holds the help text specific to this route.

  • The argument key holds the name of the argument that this route is associated with.

  • The choice key holds the name of the choice that this route is associated with.

  • The handler key holds the (local) method name, or Venus::Cli derived package, or coderef to execute when this route is matched.

  • The range key holds the range specification for the argument.

  • The wants key holds the text to be used as a value placeholder in the CLI help text.

Since 4.15

route example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $route = $cli->route('user create');

# undef
route example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $route = $cli->route('user create', {
  handler => 'handle_user_create',
});

# {
#   name => 'user create',
#   label => undef,
#   help => undef,
#   argument => undef,
#   choice => undef,
#   handler => 'handle_user_create',
#   range => undef,
#   index => 0,
# }
route example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->route('user create', {
  handler => 'handle_user_create',
});

my $route = $cli->route('user create');

# {
#   name => 'user create',
#   label => undef,
#   help => undef,
#   argument => undef,
#   choice => undef,
#   handler => 'handle_user_create',
#   range => undef,
#   index => 0,
# }
route example 4
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->route('user create', {
  handler => 'handle_user_create',
});

my $route = $cli->route('user create', undef);

# {
#   name => 'user create',
#   ...
# }

route_argument

route_argument(string $name) (maybe[hashref])

The route_argument method returns the argument configuration for the named route.

Since 4.15

route_argument example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $route_argument = $cli->route_argument;

# ""
route_argument example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('command', {
  range => ':1',
});

$cli->route('user create', {
  argument => 'command',
  handler => 'handle_user_create',
});

my $route_argument = $cli->route_argument('user create');

# {
#   name => 'command',
#   ...
# }

route_choice

route_choice(string $name) (maybe[hashref])

The route_choice method returns the choice configuration for the named route.

Since 4.15

route_choice example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $route_choice = $cli->route_choice;

# ""
route_choice example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('command', {
  range => ':1',
});

$cli->choice('user create', {
  argument => 'command',
});

$cli->route('user create', {
  argument => 'command',
  choice => 'user create',
  handler => 'handle_user_create',
});

my $route_choice = $cli->route_choice('user create');

# {
#   name => 'user create',
#   ...
# }

route_count

route_count() (number)

The route_count method returns the number of registered routes.

Since 4.15

route_count example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $route_count = $cli->route_count;

# 0
route_count example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->route('user create', {
  handler => 'handle_user_create',
});

$cli->route('user delete', {
  handler => 'handle_user_delete',
});

my $route_count = $cli->route_count;

# 2

route_handler

route_handler(string $name) (maybe[string | coderef])

The route_handler method returns the handler for the named route.

Since 4.15

route_handler example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $route_handler = $cli->route_handler;

# undef
route_handler example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->route('user create', {
  handler => 'handle_user_create',
});

my $route_handler = $cli->route_handler('user create');

# "handle_user_create"
route_handler example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $handler = sub { ... };

$cli->route('user create', {
  handler => $handler,
});

my $route_handler = $cli->route_handler('user create');

# sub { ... }

route_help

route_help(string $name) (string)

The route_help method returns the help text for the named route.

Since 4.15

route_help example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $route_help = $cli->route_help;

# ""
route_help example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->route('user create', {
  handler => 'handle_user_create',
  help => 'Create a new user',
});

my $route_help = $cli->route_help('user create');

# "Create a new user"

route_label

route_label(string $name) (string)

The route_label method returns the label for the named route.

Since 4.15

route_label example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $route_label = $cli->route_label;

# ""
route_label example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->route('user create', {
  handler => 'handle_user_create',
  label => 'User Create',
});

my $route_label = $cli->route_label('user create');

# "User Create"

route_list

route_list() (arrayref[hashref])

The route_list method returns a list of all registered route configurations in insertion order.

Since 4.15

route_list example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $route_list = $cli->route_list;

# []
route_list example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->route('user create', {
  handler => 'handle_user_create',
});

$cli->route('user delete', {
  handler => 'handle_user_delete',
});

my $route_list = $cli->route_list;

# [
#   { name => 'user create', ... },
#   { name => 'user delete', ... },
# ]

route_name

route_name(string $name) (string)

The route_name method returns the name of the named route.

Since 4.15

route_name example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $route_name = $cli->route_name;

# ""
route_name example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->route('user create', {
  handler => 'handle_user_create',
});

my $route_name = $cli->route_name('user create');

# "user create"

route_names

route_names() (arrayref[string])

The route_names method returns a list of all registered route names in insertion order.

Since 4.15

route_names example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $route_names = $cli->route_names;

# []
route_names example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->route('user create', {
  handler => 'handle_user_create',
});

$cli->route('user delete', {
  handler => 'handle_user_delete',
});

my $route_names = $cli->route_names;

# ["user create", "user delete"]

route_range

route_range(string $name) (string)

The route_range method returns the range for the named route.

Since 4.15

route_range example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $route_range = $cli->route_range;

# ""
route_range example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->route('user create', {
  handler => 'handle_user_create',
  range => ':1',
});

my $route_range = $cli->route_range('user create');

# ":1"

single

single(string $method, any @args) (any)

The single method is a configuration dispatcher and shorthand for {'multiples', false}. It returns the data or dispatches to the next configuration dispatcher based on the name provided and merges the configurations produced.

Since 4.15

single example 1
# given: synopsis

package main;

my $single = $cli->single;

# {multiples => false}
single example 2
# given: synopsis

package main;

my $single = $cli->single(undef, {type => 'boolean'});

# {multiples => false, type => 'boolean'}
single example 3
# given: synopsis

package main;

my $single = $cli->single('option', 'example');

# {
#   name => 'example',
#   label => undef,
#   help => 'Expects a string value',
#   default => undef,
#   aliases => [],
#   multiples => 0,
#   prompt => undef,
#   range => undef,
#   required => 0,
#   type => 'string',
#   index => 0,
#   wants => 'string',
# }

spec

spec(hashref $data) (Venus::Cli)

The spec method configures the CLI instance from a hashref specification. It accepts a hashref containing any of the following keys: name, version, summary, description, header, footer, arguments, options, choices, routes, and commands. The method returns the invocant.

Since 4.15

spec example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new;

my $spec = $cli->spec;

# bless(..., "Venus::Cli")
spec example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new;

my $spec = $cli->spec({
  name => 'mycli',
  version => '1.0.0',
  summary => 'My CLI application',
});

# bless(..., "Venus::Cli")
spec example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new;

my $spec = $cli->spec({
  name => 'mycli',
  options => [
    {
      name => 'verbose',
      type => 'boolean',
      aliases => ['v'],
      help => 'Enable verbose output',
    },
    {
      name => 'config',
      type => 'string',
      aliases => ['c'],
      help => 'Path to config file',
    },
  ],
});

# bless(..., "Venus::Cli")
spec example 4
package main;

use Venus::Cli;

my $cli = Venus::Cli->new;

my $spec = $cli->spec({
  name => 'mycli',
  arguments => [
    {
      name => 'input',
      type => 'string',
      help => 'Input file path',
    },
  ],
});

# bless(..., "Venus::Cli")
spec example 5
package main;

use Venus::Cli;

my $cli = Venus::Cli->new;

my $spec = $cli->spec({
  name => 'mycli',
  commands => [
    ['command', 'user', 'create', 'handle_user_create'],
    ['command', 'user', 'delete', 'handle_user_delete'],
  ],
});

# bless(..., "Venus::Cli")
spec example 6
package main;

use Venus::Cli;

my $cli = Venus::Cli->new;

my $spec = $cli->spec({
  name => 'mycli',
  version => '1.0.0',
  summary => 'User management CLI',
  description => 'A command-line tool for managing users',
  header => 'Welcome to mycli',
  footer => 'For more info, visit example.com',
  arguments => [
    {
      name => 'action',
      type => 'string',
      range => '0',
    },
  ],
  options => [
    {
      name => 'verbose',
      type => 'boolean',
      aliases => ['v'],
    },
  ],
  choices => [
    {
      name => 'create',
      argument => 'action',
      help => 'Create a new user',
    },
    {
      name => 'delete',
      argument => 'action',
      help => 'Delete a user',
    },
  ],
  routes => [
    {
      name => 'create',
      argument => 'action',
      choice => 'create',
      handler => 'handle_create',
    },
    {
      name => 'delete',
      argument => 'action',
      choice => 'delete',
      handler => 'handle_delete',
    },
  ],
});

# bless(..., "Venus::Cli")

string

string(string $method, any @args) (any)

The string method is a configuration dispatcher and shorthand for {'type', 'string'}. It returns the data or dispatches to the next configuration dispatcher based on the name provided and merges the configurations produced.

Since 4.15

string example 1
# given: synopsis

package main;

my $string = $cli->string;

# {type => 'string'}
string example 2
# given: synopsis

package main;

my $string = $cli->string(undef, {required => true});

# {type => 'string', required => true}
string example 3
# given: synopsis

package main;

my $string = $cli->string('option', 'example');

# {
#   name => 'example',
#   label => undef,
#   help => 'Expects a string value',
#   default => undef,
#   aliases => [],
#   multiples => 0,
#   prompt => undef,
#   range => undef,
#   required => 1,
#   type => 'string',
#   index => 0,
#   wants => 'string',
# }

usage

usage() (string)

The usage method provides the command-line usage information for the CLI. It outputs details such as available choices, arguments, options, and a general summary of how to use the CLI. This method is useful for users needing guidance on the various arguments, options, and choices available, and how they work.

Since 4.15

usage example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $usage = $cli->usage;

# "Usage: mycli"
usage example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(
  name => 'mycli',
  summary => 'Example summary',
);

my $usage = $cli->usage;

# "mycli - Example summary
#
# Usage: mycli"
usage example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(
  name => 'mycli',
  summary => 'Example summary',
  version => '0.0.1',
);

my $usage = $cli->usage;

# "mycli version 0.0.1 - Example summary
#
# Usage: mycli"
usage example 4
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(
  name => 'mycli',
  summary => 'Example summary',
  version => '0.0.1',
);

$cli->argument('input', {
  type => 'string',
});

$cli->argument('output', {
  type => 'string',
});

my $usage = $cli->usage;

# mycli version 0.0.1 - Example summary
#
# Usage: mycli [<input>] [<output>]
#
# Arguments:
#   [<input>]
#     Expects a string value
#     (optional)
#   [<output>]
#     Expects a string value
#     (optional)
usage example 5
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(
  name => 'mycli',
  summary => 'Example summary',
  version => '0.0.1',
);

$cli->argument('input', {
  required => true,
  type => 'string',
});

$cli->argument('output', {
  default => 'file',
  type => 'string',
});

my $usage = $cli->usage;

# mycli version 0.0.1 - Example summary
#
# Usage: mycli <input> [<output>]
#
# Arguments:
#   <input>
#     Expects a string value
#     (required)
#   [<output>]
#     Expects a string value
#     (optional)
#     Default: file
usage example 6
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(
  name => 'mycli',
  summary => 'Example summary',
  version => '0.0.1',
);

$cli->argument('input', {
  name => 'INPUT',
  type => 'string',
});

$cli->argument('output', {
  name => 'OUTPUT',
  type => 'string',
});

my $usage = $cli->usage;

# mycli version 0.0.1 - Example summary
#
# Usage: mycli [<INPUT>] [<OUTPUT>]
#
# Arguments:
#   [<INPUT>]
#     Expects a string value
#     (optional)
#   [<OUTPUT>]
#     Expects a string value
#     (optional)
usage example 7
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(
  name => 'mycli',
  summary => 'Example summary',
  version => '0.0.1',
);

$cli->argument('input', {
  name => 'input',
  label => 'Input.',
  type => 'string',
});

$cli->argument('output', {
  name => 'output',
  label => 'Output.',
  type => 'string',
});

my $usage = $cli->usage;

# mycli version 0.0.1 - Example summary
#
# Usage: mycli [<input>] [<output>]
#
# Arguments:
#   Input.
#     Expects a string value
#     (optional)
#   Output.
#     Expects a string value
#     (optional)
usage example 8
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(
  name => 'mycli',
  summary => 'Example summary',
  version => '0.0.1',
);

$cli->argument('input', {
  name => 'input',
  help => 'Provide the input device to use',
  type => 'string',
});

$cli->argument('output', {
  name => 'output',
  help => 'Provide the output device to use',
  type => 'string',
});

my $usage = $cli->usage;

# mycli version 0.0.1 - Example summary
#
# Usage: mycli [<input>] [<output>]
#
# Arguments:
#   [<input>]
#     Provide the input device to use
#     (optional)
#   [<output>]
#     Provide the output device to use
#     (optional)
usage example 9
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(
  name => 'mycli',
  summary => 'Example summary',
  version => '0.0.1',
);

$cli->argument('input', {
  name => 'input',
  help => 'Provide the input device to use',
  type => 'string',
});

$cli->argument('output', {
  name => 'output',
  help => 'Provide the output device to use',
  multiples => true,
  type => 'string',
});

my $usage = $cli->usage;

# mycli version 0.0.1 - Example summary
#
# Usage: mycli [<input>] [<output> ...]
#
# Arguments:
#   [<input>]
#     Provide the input device to use
#     (optional)
#   [<output> ...]
#     Provide the output device to use
#     (optional)
usage example 10
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(
  name => 'mycli',
);

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->argument('lines', {
  multiples => true,
  range => '0:',
  type => 'string',
});

my $usage = $cli->usage;

# Usage: mycli [<lines> ...] [--input] [--output]
#
# Arguments:
#   [<lines> ...]
#     Expects a string value
#     (optional)
#
# Options:
#   [--input=<string>]
#     Expects a string value
#     (optional)
#   [--output=<string>]
#     Expects a string value
#     (optional)
usage example 11
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(
  name => 'mycli',
);

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

$cli->option('verbose', {
  type => 'boolean',
});

$cli->option('help', {
  alias => 'h',
  type => 'boolean',
});

$cli->argument('lines', {
  multiples => true,
  range => '0:',
  type => 'string',
});

my $usage = $cli->usage;

# Usage: mycli [<lines> ...] [--input] [--output] [--verbose] [--help]
#
# Arguments:
#   [<lines> ...]
#     Expects a string value
#     (optional)
#
# Options:
#   [--input=<string>]
#     Expects a string value
#     (optional)
#   [--output=<string>]
#     Expects a string value
#     (optional)
#   [--verbose]
#     Expects a boolean value
#     (optional)
#   [-h, --help]
#     Expects a boolean value
#     (optional)
usage example 12
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(
  name => 'mycli',
);

$cli->option('input', {
  multiples => true,
  type => 'string',
});

$cli->option('output', {
  multiples => true,
  type => 'string',
});

$cli->option('verbose', {
  type => 'boolean',
});

$cli->option('help', {
  alias => 'h',
  type => 'boolean',
});

$cli->argument('lines', {
  multiples => true,
  range => '0:',
  type => 'string',
});

my $usage = $cli->usage;

# Usage: mycli [<lines> ...] [--input ...] [--output ...] [--verbose] [--help]
#
# Arguments:
#   [<lines> ...]
#     Expects a string value
#     (optional)
#
# Options:
#   [--input=<string> ...]
#     Expects a string value
#     (optional)
#   [--output=<string> ...]
#     Expects a string value
#     (optional)
#   [--verbose]
#     Expects a boolean value
#     (optional)
#   [-h, --help]
#     Expects a boolean value
#     (optional)
usage example 13
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(
  name => 'mycli',
);

$cli->option('input', {
  alias => 'i',
  multiples => true,
  required => true,
  type => 'string',
  wants => 'input',
});

$cli->option('output', {
  alias => 'o',
  multiples => true,
  type => 'string',
  wants => 'output',
});

$cli->option('verbose', {
  aliases => ['v'],
  type => 'boolean',
});

$cli->option('help', {
  aliases => ['h'],
  type => 'boolean',
});

$cli->argument('lines', {
  multiples => true,
  range => '0:',
  type => 'string',
});

my $usage = $cli->usage;

# Usage: mycli [<lines> ...] --input ... [--output ...] [--verbose] [--help]
#
# Arguments:
#   [<lines> ...]
#     Expects a string value
#     (optional)
#
# Options:
#   -i, --input=<input> ...
#     Expects a string value
#     (required)
#   [-o, --output=<output> ...]
#     Expects a string value
#     (optional)
#   [-v, --verbose]
#     Expects a boolean value
#     (optional)
#   [-h, --help]
#     Expects a boolean value
#     (optional)
usage example 14
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(
  name => 'mycli',
);

$cli->option('input', {
  alias => 'i',
  multiples => true,
  required => true,
  type => 'string',
  wants => 'input',
});

$cli->option('output', {
  alias => 'o',
  multiples => true,
  type => 'string',
  wants => 'output',
});

$cli->option('verbose', {
  aliases => ['v'],
  type => 'boolean',
});

$cli->option('help', {
  aliases => ['h'],
  type => 'boolean',
});

$cli->argument('lines', {
  multiples => true,
  range => '0:',
  type => 'string',
});

$cli->option('exit-code', {
  alias => 'ec',
  type => 'number',
  default => 0,
});

my $usage = $cli->usage;

# Usage: mycli [<lines> ...] --input ... [--output ...] [--verbose] [--help]
#              [--exit-code]
#
# Arguments:
#   [<lines> ...]
#     Expects a string value
#     (optional)
#
# Options:
#   -i, --input=<input> ...
#     Expects a string value
#     (required)
#   [-o, --output=<output> ...]
#     Expects a string value
#     (optional)
#   [-v, --verbose]
#     Expects a boolean value
#     (optional)
#   [-h, --help]
#     Expects a boolean value
#     (optional)
#   [--ec, --exit-code=<number>]
#     Expects a number value
#     (optional)
#     Default: 0
usage example 15
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(
  name => 'mycli',
);

$cli->argument('input', {
  type => 'string',
  default => 'stdin',
});

$cli->argument('output', {
  type => 'string',
  default => 'stdout',
});

$cli->option('verbose', {
  aliases => ['v'],
  type => 'boolean',
});

$cli->option('help', {
  aliases => ['h'],
  type => 'boolean',
});

$cli->option('exit-code', {
  alias => 'ec',
  type => 'number',
  default => 0,
});

$cli->choice('stdin', {
  argument => 'input',
});

$cli->choice('in-file', {
  argument => 'input',
});

$cli->choice('stdout', {
  argument => 'output',
});

$cli->choice('out-file', {
  argument => 'output',
});

my $usage = $cli->usage;

# Usage: mycli [<input>] [<output>] [--verbose] [--help] [--exit-code]
#
# Arguments:
#   [<input>]
#     Expects a string value
#     (optional)
#     Default: stdin
#   [<output>]
#     Expects a string value
#     (optional)
#     Default: stdout
#
# Options:
#   [-v, --verbose]
#     Expects a boolean value
#     (optional)
#   [-h, --help]
#     Expects a boolean value
#     (optional)
#   [--ec, --exit-code=<number>]
#     Expects a number value
#     (optional)
#     Default: 0
#
# Choices for [<input>]:
#   stdin
#     Expects a string value
#     [<input>]
#   in-file
#     Expects a string value
#     [<input>]
#
# Choices for [<output>]:
#   stdout
#     Expects a string value
#     [<output>]
#   out-file
#     Expects a string value
#     [<output>]
usage example 16
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(
  name => 'mycli',
);

$cli->argument('choice', {
  help => 'See "choices" below',
  type => 'string',
  default => 'open',
});

$cli->choice('open', {
  argument => 'choice',
});

$cli->choice('close', {
  argument => 'choice',
});

$cli->choice('read', {
  argument => 'choice',
});

$cli->choice('write', {
  argument => 'choice',
});

my $usage = $cli->usage;

# Usage: mycli [<choice>]
#
# Arguments:
#   [<choice>]
#     See "choices" below
#     (optional)
#     Default: open
#
# Choices for [<choice>]:
#   open
#     Expects a string value
#     [<choice>]
#   close
#     Expects a string value
#     [<choice>]
#   read
#     Expects a string value
#     [<choice>]
#   write
#     Expects a string value
#     [<choice>]
usage example 17
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(
  name => 'mycli',
);

$cli->argument('choice', {
  help => 'See "choices" below',
  type => 'string',
  required => true,
});

$cli->choice('open', {
  argument => 'choice',
});

$cli->choice('close', {
  argument => 'choice',
});

$cli->choice('read', {
  argument => 'choice',
});

$cli->choice('write', {
  argument => 'choice',
});

my $usage = $cli->usage;

# Usage: mycli <choice>
#
# Arguments:
#   <choice>
#     See "choices" below
#     (required)
#
# Choices for <choice>:
#   open
#     Expects a string value
#     <choice>
#   close
#     Expects a string value
#     <choice>
#   read
#     Expects a string value
#     <choice>
#   write
#     Expects a string value
#     <choice>

usage_argument_default

usage_argument_default(string $name) (string)

The usage_argument_default method renders the default configuration value for the named argument for use in the CLI "usage" text.

Since 4.15

usage_argument_default example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $usage_argument_default = $cli->usage_argument_default;

# ""
usage_argument_default example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  default => 'stdin',
});

my $usage_argument_default = $cli->usage_argument_default('input');

# "Default: stdin"
usage_argument_default example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  default => ['stdin', 'file'],
});

my $usage_argument_default = $cli->usage_argument_default('input');

# "Default: stdin, file"

usage_argument_help

usage_argument_help(string $name) (string)

The usage_argument_help method renders the help configuration value for the named argument for use in the CLI "usage" text.

Since 4.15

usage_argument_help example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $usage_argument_help = $cli->usage_argument_help;

# ""
usage_argument_help example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  help => 'Provide input.',
});

my $usage_argument_help = $cli->usage_argument_help('input');

# "Provide input."

usage_argument_label

usage_argument_label(string $name) (string)

The usage_argument_label method renders the label configuration value for the named argument for use in the CLI "usage" text.

Since 4.15

usage_argument_label example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $usage_argument_label = $cli->usage_argument_label;

# ""
usage_argument_label example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  label => 'Input.',
});

my $usage_argument_label = $cli->usage_argument_label('input');

# "Input."

usage_argument_required

usage_argument_required(string $name) (string)

The usage_argument_required method renders the required configuration value for the named argument for use in the CLI "usage" text.

Since 4.15

usage_argument_required example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $usage_argument_required = $cli->usage_argument_required;

# "(optional)"
usage_argument_required example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  required => true,
});

my $usage_argument_required = $cli->usage_argument_required('input');

# "(required)"
usage_argument_required example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  required => false,
});

my $usage_argument_required = $cli->usage_argument_required('input');

# "(optional)"

usage_argument_token

usage_argument_token(string $name) (string)

The usage_argument_token method renders the token configuration value for the named argument for use in the CLI "usage" text.

Since 4.15

usage_argument_token example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $usage_argument_token = $cli->usage_argument_token;

# ""
usage_argument_token example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  required => true,
  multiples => false,
  type => 'string',
});

my $usage_argument_token = $cli->usage_argument_token('input');

# "<input>"
usage_argument_token example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  required => true,
  multiples => true,
  type => 'string',
});

my $usage_argument_token = $cli->usage_argument_token('input');

# "<input> ..."
usage_argument_token example 4
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  required => false,
  multiples => false,
  type => 'string',
});

my $usage_argument_token = $cli->usage_argument_token('input');

# "[<input>]"
usage_argument_token example 5
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  required => false,
  multiples => true,
  type => 'string',
});

my $usage_argument_token = $cli->usage_argument_token('input');

# "[<input> ...]"

usage_arguments

usage_arguments() (string)

The usage_arguments method renders all registered arguments for use in the CLI "usage" text.

Since 4.15

usage_arguments example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  type => 'string',
});

$cli->argument('output', {
  type => 'string',
});

my $usage_arguments = $cli->usage_arguments;

# Arguments:
#   [<input>]
#     Expects a string value
#     (optional)
#   [<output>]
#     Expects a string value
#     (optional)
usage_arguments example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  required => true,
  type => 'string',
});

$cli->argument('output', {
  required => true,
  type => 'string',
});

my $usage_arguments = $cli->usage_arguments;

# Arguments:
#   <input>
#     Expects a string value
#     (required)
#   <output>
#     Expects a string value
#     (required)

usage_choice_help

usage_choice_help(string $name) (string)

The usage_choice_help method renders the help configuration value for the named choice for use in the CLI "usage" text.

Since 4.15

usage_choice_help example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $usage_choice_help = $cli->usage_choice_help;

# ""
usage_choice_help example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  help => 'Example help',
});

$cli->choice('stdin', {
  argument => 'input',
});

my $usage_choice_help = $cli->usage_choice_help('stdin');

# "Expects a string value"
usage_choice_help example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  help => 'Example help',
});

$cli->choice('stdin', {
  argument => 'input',
  help => 'Example help',
});

my $usage_choice_help = $cli->usage_choice_help('stdin');

# "Example help"

usage_choice_label

usage_choice_label(string $name) (string)

The usage_choice_label method renders the label configuration value for the named choice for use in the CLI "usage" text.

Since 4.15

usage_choice_label example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $usage_choice_label = $cli->usage_choice_label;

# ""
usage_choice_label example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  label => 'Input.',
  type => 'string',
});

$cli->choice('stdin', {
  argument => 'input',
});

my $usage_choice_label = $cli->usage_choice_label('stdin');

# "stdin"
usage_choice_label example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  label => 'Input.',
  type => 'string',
});

$cli->choice('stdin', {
  label => 'Stdin',
  argument => 'input',
});

my $usage_choice_label = $cli->usage_choice_label('stdin');

# "Stdin"

usage_choice_required

usage_choice_required(string $name) (string)

The usage_choice_required method renders the required configuration value for the named choice for use in the CLI "usage" text.

Since 4.15

usage_choice_required example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $usage_choice_required = $cli->usage_choice_required;

# ""
usage_choice_required example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  required => true,
});

$cli->choice('stdin', {
  argument => 'input',
});

my $usage_choice_required = $cli->usage_choice_required('stdin');

# "<input>"
usage_choice_required example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  required => false,
});

$cli->choice('stdin', {
  argument => 'input',
});

my $usage_choice_required = $cli->usage_choice_required('stdin');

# "[<input>]"

usage_choices

usage_choices() (string)

The usage_choices method renders all registered choices for use in the CLI "usage" text.

Since 4.15

usage_choices example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  type => 'string',
});

$cli->choice('stdin', {
  argument => 'input',
});

$cli->argument('output', {
  type => 'string',
});

$cli->choice('stdout', {
  argument => 'output',
});

my $usage_choices = $cli->usage_choices;

# Choices for [<input>]:
#   stdin
#     Expects a string value
#     [<input>]
#
# Choices for [<output>]:
#   stdout
#     Expects a string value
#     [<output>]
usage_choices example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  required => true,
});

$cli->choice('stdin', {
  argument => 'input',
  help => 'Use STDIN',
});

$cli->argument('output', {
  default => 'stdout',
});

$cli->choice('stdout', {
  argument => 'output',
  help => 'Use STDOUT',
});

my $usage_choices = $cli->usage_choices;

# Choices for <input>:
#   stdin
#     Use STDIN
#     <input>
#
# Choices for [<output>]:
#   stdout
#     Use STDOUT
#     [<output>]

usage_description

usage_description() (string)

The usage_description method renders the description for use in the CLI "usage" text.

Since 4.15

usage_description example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $description = $cli->description('Example description');

my $usage_description = $cli->usage_description;

# "Example description"
usage_footer() (string)

The usage_footer method renders the footer for use in the CLI "usage" text.

Since 4.15

package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $footer = $cli->footer('Example footer');

my $usage_footer = $cli->usage_footer;

# "Example footer"

usage_gist

usage_gist() (string)

The usage_gist method renders the CLI top-line describing the name, version, and/or summary.

Since 4.15

usage_gist example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $usage_gist = $cli->usage_gist;

# ""
usage_gist example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->version('0.0.1');

my $usage_gist = $cli->usage_gist;

# "mycli version 0.0.1"
usage_gist example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->summary('Example summary');

my $usage_gist = $cli->usage_gist;

# "mycli - Example summary"
usage_gist example 4
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->version('0.0.1');

$cli->summary('Example summary');

my $usage_gist = $cli->usage_gist;

# "mycli version 0.0.1 - Example summary"

usage_header

usage_header() (string)

The usage_header method renders the header for use in the CLI "usage" text.

Since 4.15

usage_header example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $header = $cli->header('Example header');

my $usage_header = $cli->usage_header;

# "Example header"

usage_line

usage_line() (string)

The usage_line method renders the CLI usage line for use in the CLI "usage" text.

Since 4.15

usage_line example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $usage_line = $cli->usage_line;

# "Usage: mycli"
usage_line example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  type => 'string',
});

my $usage_line = $cli->usage_line;

# "Usage: mycli [<input>]"
usage_line example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  type => 'string',
});

$cli->argument('output', {
  type => 'string',
});

my $usage_line = $cli->usage_line;

# "Usage: mycli [<input>] [<output>]"
usage_line example 4
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  required => true,
  type => 'string',
});

$cli->argument('output', {
  required => true,
  type => 'string',
});

my $usage_line = $cli->usage_line;

# "Usage: mycli <input> <output>"
usage_line example 5
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->argument('input', {
  required => true,
  type => 'string',
});

$cli->argument('output', {
  multiples => true,
  required => false,
  type => 'string',
});

my $usage_line = $cli->usage_line;

# "Usage: mycli <input> [<output> ...]"

usage_name

usage_name() (string)

The usage_name method renders the CLI name for use in the CLI "usage" text.

Since 4.15

usage_name example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new;

my $usage_name = $cli->usage_name;

# ""
usage_name example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $usage_name = $cli->usage_name;

# "mycli"

usage_option_default

usage_option_default(string $name) (string)

The usage_option_default method renders the default configuration value for the named option for use in the CLI "usage" text.

Since 4.15

usage_option_default example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $usage_option_default = $cli->usage_option_default;

# ""
usage_option_default example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  default => 'stdin',
});

my $usage_option_default = $cli->usage_option_default('input');

# "Default: stdin"
usage_option_default example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  default => ['stdin', 'file'],
});

my $usage_option_default = $cli->usage_option_default('input');

# "Default: stdin, file"

usage_option_help

usage_option_help(string $name) (string)

The usage_option_help method renders the help configuration value for the named option for use in the CLI "usage" text.

Since 4.15

usage_option_help example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $usage_option_help = $cli->usage_option_help;

# ""
usage_option_help example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  help => 'Example help',
});

my $usage_option_help = $cli->usage_option_help('input');

# "Example help"

usage_option_label

usage_option_label(string $name) (string)

The usage_option_label method renders the label configuration value for the named option for use in the CLI "usage" text.

Since 4.15

usage_option_label example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $usage_option_label = $cli->usage_option_label;

# ""
usage_option_label example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  required => true,
});

my $usage_option_label = $cli->usage_option_label('input');

# "--input=<string>"
usage_option_label example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  multiples => true,
  required => true,
});

my $usage_option_label = $cli->usage_option_label('input');

# "--input=<string> ..."
usage_option_label example 4
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  multiples => true,
  required => true,
  type => 'number',
});

my $usage_option_label = $cli->usage_option_label('input');

# "--input=<number> ..."
usage_option_label example 5
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  multiples => true,
  required => true,
  type => 'number',
  wants => 'input',
});

my $usage_option_label = $cli->usage_option_label('input');

# "--input=<input> ..."
usage_option_label example 6
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  required => false,
});

my $usage_option_label = $cli->usage_option_label('input');

# "[--input=<string>]"
usage_option_label example 7
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  multiples => true,
  required => false,
});

my $usage_option_label = $cli->usage_option_label('input');

# "[--input=<string> ...]"
usage_option_label example 8
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  multiples => true,
  required => false,
  type => 'number',
});

my $usage_option_label = $cli->usage_option_label('input');

# "[--input=<number> ...]"
usage_option_label example 9
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  multiples => true,
  required => false,
  type => 'number',
  wants => 'input',
});

my $usage_option_label = $cli->usage_option_label('input');

# "[--input=<input> ...]"
usage_option_label example 10
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  multiples => true,
  required => false,
  type => 'boolean',
  wants => undef,
});

my $usage_option_label = $cli->usage_option_label('input');

# "[--input ...]"

usage_option_required

usage_option_required(string $name) (string)

The usage_option_required method renders the required configuration value for the named option for use in the CLI "usage" text.

Since 4.15

usage_option_required example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $usage_option_required = $cli->usage_option_required;

# "(optional)"
usage_option_required example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  required => true,
});

my $usage_option_required = $cli->usage_option_required('input');

# "(required)"
usage_option_required example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  required => false,
});

my $usage_option_required = $cli->usage_option_required('input');

# "(optional)"

usage_option_token

usage_option_token(string $name) (string)

The usage_option_token method renders the token configuration value for the named option for use in the CLI "usage" text.

Since 4.15

usage_option_token example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $usage_option_token = $cli->usage_option_token;

# ""
usage_option_token example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  required => true,
});

my $usage_option_token = $cli->usage_option_token('input');

# "--input"
usage_option_token example 3
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  multiples => true,
  required => true,
});

my $usage_option_token = $cli->usage_option_token('input');

# "--input ..."
usage_option_token example 4
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  required => false,
});

my $usage_option_token = $cli->usage_option_token('input');

# "[--input]"
usage_option_token example 5
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  multiples => true,
  required => false,
});

my $usage_option_token = $cli->usage_option_token('input');

# "[--input ...]"

usage_options

usage_options() (string)

The usage_options method renders all registered options for use in the CLI "usage" text.

Since 4.15

usage_options example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  type => 'string',
});

$cli->option('output', {
  type => 'string',
});

my $usage_options = $cli->usage_options;

# Options:
#   [--input=<string>]
#     Expects a string value
#     (optional)
#   [--output=<string>]
#     Expects a string value
#     (optional)
usage_options example 2
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

$cli->option('input', {
  required => true,
  type => 'string',
});

$cli->option('output', {
  required => true,
  type => 'string',
});

my $usage_options = $cli->usage_options;

# Options:
#   --input=<string>
#     Expects a string value
#     (required)
#   --output=<string>
#     Expects a string value
#     (required)

usage_summary

usage_summary() (string)

The usage_summary method renders the summary for use in the CLI "usage" text.

Since 4.15

usage_summary example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $summary = $cli->summary('Example summary');

my $usage_summary = $cli->usage_summary;

# "Example summary"

usage_version

usage_version() (string)

The usage_version method renders the description for use in the CLI "usage" text.

Since 4.15

usage_version example 1
package main;

use Venus::Cli;

my $cli = Venus::Cli->new(name => 'mycli');

my $version = $cli->version('0.0.1');

my $usage_version = $cli->usage_version;

# "0.0.1"

vars

vars() (Venus::Vars)

The vars method returns the list of parsed command-line options as a Venus::Vars object.

Since 4.15

vars example 1
# given: synopsis

package main;

my $vars = $cli->vars;

# bless(..., "Venus::Vars")

yesno

yesno(string $method, any @args) (any)

The yesno method is a configuration dispatcher and shorthand for {'type', 'yesno'}. It returns the data or dispatches to the next configuration dispatcher based on the name provided and merges the configurations produced.

Since 4.15

yesno example 1
# given: synopsis

package main;

my $yesno = $cli->yesno;

# {type => 'yesno'}
yesno example 2
# given: synopsis

package main;

my $yesno = $cli->yesno(undef, {required => true});

# {type => 'yesno', required => true}
yesno example 3
# given: synopsis

package main;

my $yesno = $cli->yesno('option', 'example');

# {
#   name => 'example',
#   label => undef,
#   help => 'Expects a yesno value',
#   default => undef,
#   aliases => [],
#   multiples => 0,
#   prompt => undef,
#   range => undef,
#   required => 1,
#   type => 'yesno',
#   index => 0,
#   wants => 'yesno',
# }

AUTHORS

Awncorp, awncorp@cpan.org

LICENSE

Copyright (C) 2022, Awncorp, awncorp@cpan.org.

This program is free software, you can redistribute it and/or modify it under the terms of the Apache license version 2.0.