Venus::Cli

Cli Class

Cli Class for Perl 5

method: arg method: execute method: exit method: fail method: help method: log_debug method: log_error method: log_fatal method: log_info method: log_trace method: log_warn method: okay method: opt method: options

package main;

use Venus::Cli;

my $cli = Venus::Cli->new(['example', '--help']);

# $cli->program;

# "/path/to/executable"

# $cli->arg(0);

# "example"

# $cli->opt('help');

# 1

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

Venus::Kind::Utility

Venus::Role::Optional

The args attribute holds a Venus::Args object.

args(Args $data) (Args)

{ since => '1.71', }

=example-1 args

# given: synopsis

package main;

my $args = $cli->args;

The data attribute holds a Venus::Data object.

data(Data $data) (Data)

{ since => '1.71', }

=example-1 data

# given: synopsis

package main;

my $data = $cli->data;

The init attribute holds the "initial" raw arguments provided to the CLI, defaulting to [@ARGV], used by "args" and "opts".

init(ArrayRef $data) (ArrayRef)

{ since => '1.68', }

=example-1 init

# given: synopsis

package main;

my $init = $cli->init;

# ["example", "--help"]

The logs attribute holds a Venus::Logs object.

logs(Logs $logs) (Logs)

{ since => '1.71', }

=example-1 logs

# given: synopsis

package main;

my $logs = $cli->logs;

The opts attribute holds a Venus::Opts object.

opts(Opts $opts) (Opts)

{ since => '1.71', }

=example-1 opts

# given: synopsis

package main;

my $opts = $cli->opts;

The path attribute holds a Venus::Path object, meant to represent the path of the file where the CLI executable and POD is.

path(Path $data) (Path)

{ since => '1.71', }

=example-1 path

# given: synopsis

package main;

my $path = $cli->path;

The vars attribute holds a Venus::Vars object.

vars(Vars $vars) (Vars)

{ since => '1.71', }

=example-1 vars

# given: synopsis

package main;

my $vars = $cli->vars;

The arg method returns the element specified by the index in the unnamed arguments list, i.e. arguments not parsed as options.

arg(Str $pos) (Str)

{ since => '1.68', }

=example-1 arg

# given: synopsis

package main;

my $arg = $cli->arg;

# undef

The execute method is the default entrypoint of the program and runs the application.

execute() (Any)

{ since => '1.68', }

=example-1 execute

package main;

use Venus::Cli;

my $cli = Venus::Cli->new([]);

# e.g.

# sub execute {
#   my ($self) = @_;
#
#   return $self->opt('help') ? $self->okay : $self->fail;
# }

# my $result = $cli->execute;

# ...

The exit method exits the program using the exit code provided. The exit code defaults to 0. Optionally, you can dispatch before exiting by providing a method name or coderef, and arguments.

exit(Int $code, Str|CodeRef $code, Any @args) (Any)

{ since => '1.68', }

=example-1 exit

# given: synopsis

package main;

my $exit = $cli->exit;

# ()

The fail method exits the program with the exit code 1. Optionally, you can dispatch before exiting by providing a method name or coderef, and arguments.

fail(Str|CodeRef $code, Any @args) (Any)

{ since => '1.68', }

=example-1 fail

# given: synopsis

package main;

my $fail = $cli->fail;

# ()

The help method returns the POD found in the file specified by the "podfile" method, defaulting to the =head1 OPTIONS section.

help(Str @data) (Str)

{ since => '1.68', }

=example-1 help

# given: synopsis

package main;

my $help = $cli->help;

# ""

The log_debug method logs debug information.

log_debug(Str @data) (Log)

{ since => '1.68', }

=example-1 log_debug

# given: synopsis

package main;

# $cli->logs->level('trace');

# my $log = $cli->log_debug(time, 'Something failed!');

# "0000000000 Something failed!"

The log_error method logs error information.

log_error(Str @data) (Log)

{ since => '1.68', }

=example-1 log_error

# given: synopsis

package main;

# $cli->logs->level('trace');

# my $log = $cli->log_error(time, 'Something failed!');

# "0000000000 Something failed!"

The log_fatal method logs fatal information.

log_fatal(Str @data) (Log)

{ since => '1.68', }

=example-1 log_fatal

# given: synopsis

package main;

# $cli->logs->level('trace');

# my $log = $cli->log_fatal(time, 'Something failed!');

# "0000000000 Something failed!"

The log_info method logs info information.

log_info(Str @data) (Log)

{ since => '1.68', }

=example-1 log_info

# given: synopsis

package main;

# $cli->logs->level('trace');

# my $log = $cli->log_info(time, 'Something failed!');

# "0000000000 Something failed!"

The log_trace method logs trace information.

log_trace(Str @data) (Log)

{ since => '1.68', }

=example-1 log_trace

# given: synopsis

package main;

# $cli->logs->level('trace');

# my $log = $cli->log_trace(time, 'Something failed!');

# "0000000000 Something failed!"

The log_warn method logs warn information.

log_warn(Str @data) (Log)

{ since => '1.68', }

=example-1 log_warn

# given: synopsis

package main;

# $cli->logs->level('trace');

# my $log = $cli->log_warn(time, 'Something failed!');

# "0000000000 Something failed!"

The okay method exits the program with the exit code 0. Optionally, you can dispatch before exiting by providing a method name or coderef, and arguments.

okay(Str|CodeRef $code, Any @args) (Any)

{ since => '1.68', }

=example-1 okay

# given: synopsis

package main;

my $okay = $cli->okay;

# ()

The opt method returns the named option specified by the "options" method.

opt(Str $name) (Str)

{ since => '1.68', }

=example-1 opt

# given: synopsis

package main;

my $opt = $cli->opt;

# undef

The options method returns the list of Getopt::Long definitions.

options() (ArrayRef)

{ since => '1.68', }

=example-1 options

# given: synopsis

package main;

my $options = $cli->options;

# ['help|h']

t/Venus.t: pdml: authors t/Venus.t: pdml: license

81 POD Errors

The following errors were encountered while parsing the POD:

Around line 21:

Unknown directive: =name

Around line 29:

Unknown directive: =tagline

Around line 37:

Unknown directive: =abstract

Around line 45:

Unknown directive: =includes

Around line 66:

Unknown directive: =synopsis

Around line 97:

Unknown directive: =description

Around line 106:

Unknown directive: =inherits

Around line 114:

Unknown directive: =integrates

Around line 122:

Unknown directive: =attribute

Around line 126:

Unknown directive: =signature

Around line 130:

Unknown directive: =metadata

Around line 154:

Unknown directive: =attribute

Around line 158:

Unknown directive: =signature

Around line 162:

Unknown directive: =metadata

Around line 186:

Unknown directive: =attribute

Around line 191:

Unknown directive: =signature

Around line 195:

Unknown directive: =metadata

Around line 221:

Unknown directive: =attribute

Around line 225:

Unknown directive: =signature

Around line 229:

Unknown directive: =metadata

Around line 253:

Unknown directive: =attribute

Around line 257:

Unknown directive: =signature

Around line 261:

Unknown directive: =metadata

Around line 285:

Unknown directive: =attribute

Around line 290:

Unknown directive: =signature

Around line 294:

Unknown directive: =metadata

Around line 318:

Unknown directive: =attribute

Around line 322:

Unknown directive: =signature

Around line 326:

Unknown directive: =metadata

Around line 350:

Unknown directive: =method

Around line 355:

Unknown directive: =signature

Around line 359:

Unknown directive: =metadata

Around line 394:

=cut found outside a pod block. Skipping to next block.

Around line 404:

Unknown directive: =method

Around line 409:

Unknown directive: =signature

Around line 413:

Unknown directive: =metadata

Around line 471:

=cut found outside a pod block. Skipping to next block.

Around line 483:

Unknown directive: =method

Around line 489:

Unknown directive: =signature

Around line 493:

Unknown directive: =metadata

Around line 529:

=cut found outside a pod block. Skipping to next block.

Around line 549:

=cut found outside a pod block. Skipping to next block.

Around line 569:

=cut found outside a pod block. Skipping to next block.

Around line 584:

Unknown directive: =method

Around line 589:

Unknown directive: =signature

Around line 593:

Unknown directive: =metadata

Around line 629:

=cut found outside a pod block. Skipping to next block.

Around line 645:

Unknown directive: =method

Around line 650:

Unknown directive: =signature

Around line 654:

Unknown directive: =metadata

Around line 689:

=cut found outside a pod block. Skipping to next block.

Around line 701:

Unknown directive: =method

Around line 705:

Unknown directive: =signature

Around line 709:

Unknown directive: =metadata

Around line 743:

Unknown directive: =method

Around line 747:

Unknown directive: =signature

Around line 751:

Unknown directive: =metadata

Around line 785:

Unknown directive: =method

Around line 789:

Unknown directive: =signature

Around line 793:

Unknown directive: =metadata

Around line 827:

Unknown directive: =method

Around line 831:

Unknown directive: =signature

Around line 835:

Unknown directive: =metadata

Around line 869:

Unknown directive: =method

Around line 873:

Unknown directive: =signature

Around line 877:

Unknown directive: =metadata

Around line 911:

Unknown directive: =method

Around line 915:

Unknown directive: =signature

Around line 919:

Unknown directive: =metadata

Around line 953:

Unknown directive: =method

Around line 958:

Unknown directive: =signature

Around line 962:

Unknown directive: =metadata

Around line 998:

=cut found outside a pod block. Skipping to next block.

Around line 1014:

Unknown directive: =method

Around line 1018:

Unknown directive: =signature

Around line 1022:

Unknown directive: =metadata

Around line 1057:

=cut found outside a pod block. Skipping to next block.

Around line 1067:

Unknown directive: =method

Around line 1071:

Unknown directive: =signature

Around line 1075:

Unknown directive: =metadata

Around line 1101:

Unknown directive: =partials