Perinci-CmdLine-Classic
view release on metacpan or search on metacpan
lib/Perinci/CmdLine/Classic/Role/Help.pm view on Meta::CPAN
}
if ($self->subcommands && !$r->{subcommand_name}) {
if (defined $self->default_subcommand) {
$ct .= ($ct ? "\n" : "") . $pn .
" " . __("--cmd=<other-subcommand> [options]");
} else {
$ct .= ($ct ? "\n" : "") . $pn .
" " . __("<subcommand> [options]");
}
} else {
my $usage = $r->{_help_clidocdata}{usage_line};
$usage =~ s/\[\[prog\]\]/$pn/;
$usage =~ s/\[options\]/__("[options]")/e;
$ct .= ($ct ? "\n" : "") . $usage;
}
$self->_help_add_heading($r, __("Usage"));
$self->_help_add_row($r, [$ct], {indent=>1});
}
sub help_section_options {
my ($self, $r) = @_;
my $opts = $r->{_help_clidocdata}{opts};
return unless keys %$opts;
my $verbose = $r->{_help_verbose};
my $info = $r->{_help_info};
my $meta = $r->{_help_meta};
my $args_p = $meta->{args};
my $sc = $self->subcommands;
# group options by raw category, e.g. $cats{""} (for options
# without category and common options) or $cat{"cat1"}.
lib/Perinci/CmdLine/Classic/Role/Help.pm view on Meta::CPAN
$self->_help_add_heading($r, __("Description"));
$self->_help_add_row($r, [$desc], {wrap=>1, indent=>1});
}
sub help_section_examples {
my ($self, $r) = @_;
my $verbose = $r->{_help_verbose};
my $meta = $r->{_help_meta};
my $egs = $r->{_help_clidocdata}{examples};
return unless $egs && @$egs;
$self->_help_add_heading($r, __("Examples"));
my $pn = $self->_color(
'program_name', $self->get_program_and_subcommand_name($r));
for my $eg (@$egs) {
my $cmdline = $eg->{cmdline};
$cmdline =~ s/\[\[prog\]\]/$pn/;
$self->_help_add_row($r, ["% $cmdline"], {indent=>1});
if ($verbose) {
lib/Perinci/CmdLine/Classic/Role/Help.pm view on Meta::CPAN
die [500, "Can't info '$url': $res->[0] - $res->[1]"]
unless $res->[0] == 200;
$r->{_help_info} = $res->[2];
$res = $self->riap_client->request(meta => $url);
die [500, "Can't meta '$url': $res->[0] - $res->[1]"]
unless $res->[0] == 200;
$r->{_help_meta} = $res->[2]; # cache here
}
# get cli opt spec
unless ($r->{_help_clidocdata}) {
require Perinci::Sub::To::CLIDocData;
my $res = Perinci::Sub::To::CLIDocData::gen_cli_doc_data_from_meta(
meta => $r->{_help_meta}, meta_is_normalized => 1,
common_opts => $self->common_opts,
per_arg_json => $self->per_arg_json,
per_arg_yaml => $self->per_arg_yaml,
);
die [500, "Can't gen_cli_doc_data_from_meta: $res->[0] - $res->[1]"]
unless $res->[0] == 200;
$r->{_help_clidocdata} = $res->[2]; # cache here
}
# ux: since --verbose will potentially show lots of paragraph text, let's
# default to 80 and not wider width, unless user specifically requests
# column width via COLUMNS.
if ($verbose && !defined($ENV{COLUMNS}) && $self->term_width > 80) {
$self->term_width(80);
}
# determine which help sections should we generate
( run in 0.247 second using v1.01-cache-2.11-cpan-454fe037f31 )