Venus::Cli - Cli Class
Cli Class for Perl 5
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.
This package has the following attributes:
args(Args $data) (Args)
The args attribute holds a Venus::Args object.
Since 1.71
1.71
# given: synopsis package main; my $args = $cli->args;
data(Data $data) (Data)
The data attribute holds a Venus::Data object.
# given: synopsis package main; my $data = $cli->data;
init(ArrayRef $data) (ArrayRef)
The init attribute holds the "initial" raw arguments provided to the CLI, defaulting to [@ARGV], used by "args" and "opts".
[@ARGV]
Since 1.68
1.68
# given: synopsis package main; my $init = $cli->init; # ["example", "--help"]
logs(Logs $logs) (Logs)
The logs attribute holds a Venus::Logs object.
# given: synopsis package main; my $logs = $cli->logs;
opts(Opts $opts) (Opts)
The opts attribute holds a Venus::Opts object.
# given: synopsis package main; my $opts = $cli->opts;
path(Path $data) (Path)
The path attribute holds a Venus::Path object, meant to represent the path of the file where the CLI executable and POD is.
# given: synopsis package main; my $path = $cli->path;
vars(Vars $vars) (Vars)
The vars attribute holds a Venus::Vars object.
# given: synopsis package main; my $vars = $cli->vars;
This package inherits behaviors from:
Venus::Kind::Utility
This package integrates behaviors from:
Venus::Role::Optional
This package provides the following methods:
arg(Str $pos) (Str)
The arg method returns the element specified by the index in the unnamed arguments list, i.e. arguments not parsed as options.
# given: synopsis package main; my $arg = $cli->arg; # undef
# given: synopsis package main; my $arg = $cli->arg(0); # "example"
execute() (Any)
The execute method is the default entrypoint of the program and runs the application.
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; # ...
package main; use Venus::Cli; my $cli = Venus::Cli->new(['--help']); # e.g. # sub execute { # my ($self) = @_; # # return $self->opt('help') ? $self->okay : $self->fail; # } # my $result = $cli->execute; # ...
exit(Int $code, Str|CodeRef $code, Any @args) (Any)
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.
0
# given: synopsis package main; my $exit = $cli->exit; # ()
# given: synopsis package main; my $exit = $cli->exit(0); # ()
# given: synopsis package main; my $exit = $cli->exit(1); # ()
# given: synopsis package main; # my $exit = $cli->exit(1, 'log_info', 'Something failed!'); # ()
fail(Str|CodeRef $code, Any @args) (Any)
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.
1
# given: synopsis package main; my $fail = $cli->fail; # ()
# given: synopsis package main; # my $fail = $cli->fail('log_info', 'Something failed!'); # ()
help(Str @data) (Str)
The help method returns the POD found in the file specified by the "podfile" method, defaulting to the =head1 OPTIONS section.
=head1 OPTIONS
# given: synopsis package main; my $help = $cli->help; # ""
# given: synopsis package main; # my $help = $cli->help('head1', 'NAME'); # "Example"
log_debug(Str @data) (Log)
The log_debug method logs debug information.
debug
# given: synopsis package main; # $cli->logs->level('trace'); # my $log = $cli->log_debug(time, 'Something failed!'); # "0000000000 Something failed!"
log_error(Str @data) (Log)
The log_error method logs error information.
error
# given: synopsis package main; # $cli->logs->level('trace'); # my $log = $cli->log_error(time, 'Something failed!'); # "0000000000 Something failed!"
log_fatal(Str @data) (Log)
The log_fatal method logs fatal information.
fatal
# given: synopsis package main; # $cli->logs->level('trace'); # my $log = $cli->log_fatal(time, 'Something failed!'); # "0000000000 Something failed!"
log_info(Str @data) (Log)
The log_info method logs info information.
info
# given: synopsis package main; # $cli->logs->level('trace'); # my $log = $cli->log_info(time, 'Something failed!'); # "0000000000 Something failed!"
log_trace(Str @data) (Log)
The log_trace method logs trace information.
trace
# given: synopsis package main; # $cli->logs->level('trace'); # my $log = $cli->log_trace(time, 'Something failed!'); # "0000000000 Something failed!"
log_warn(Str @data) (Log)
The log_warn method logs warn information.
warn
# given: synopsis package main; # $cli->logs->level('trace'); # my $log = $cli->log_warn(time, 'Something failed!'); # "0000000000 Something failed!"
okay(Str|CodeRef $code, Any @args) (Any)
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.
# given: synopsis package main; my $okay = $cli->okay; # ()
# given: synopsis package main; # my $okay = $cli->okay('log_info', 'Something worked!'); # ()
opt(Str $name) (Str)
The opt method returns the named option specified by the "options" method.
# given: synopsis package main; my $opt = $cli->opt; # undef
# given: synopsis package main; my $opt = $cli->opt('help'); # 1
options() (ArrayRef)
The options method returns the list of Getopt::Long definitions.
# given: synopsis package main; my $options = $cli->options; # ['help|h']
To install Venus, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Venus
CPAN shell
perl -MCPAN -e shell install Venus
For more information on module installation, please visit the detailed CPAN module installation guide.