| 1 | #============================================================================= | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # Module: Term::CLI::Command::Help | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # Description: Class for Term::CLI 'help' command. | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # Author: Steven Bakker (SBAKKER), <sbakker@cpan.org> | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # Created: 18/Feb/2018 | ||||||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # Copyright (c) 2018-2022 Steven Bakker | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # This module is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||
| 13 | # it under the same terms as Perl itself. See "perldoc perlartistic." | ||||||||||||||||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||||||||||||||||
| 15 | # This software is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||||||||||||||||
| 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||||||||||||||||
| 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||||||||||||||||||||||||||||||||||||||||||
| 18 | # | ||||||||||||||||||||||||||||||||||||||||||
| 19 | #============================================================================= | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | package Term::CLI::Command::Help 0.061000; | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 6 | ▶ | use 5.014; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 6 | ▶ | use version; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 6 | ▶ | use List::Util 1.23 qw( first min ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 6 | ▶ | use Types::Standard 1.000005 qw( ArrayRef Str ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 6 | ▶ | use Term::CLI::Util qw( is_prefix_str get_options_from_array ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 6 | ▶ | use Term::CLI::L10N qw( loc ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 6 | ▶ | use Pod::Text::Termcap 2.06; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 6 | ▶ | use Pod::Text::Overstrike 2.04; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 6 | ▶ | my $POD_PARSER_CLASS = $Pod::Text::Termcap::VERSION >= 4.11 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | ? 'Pod::Text::Termcap' | ||||||||||||||||||||||||||||||||||||||||||
| 37 | : 'Pod::Text::Overstrike'; | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 6 | ▶ | use Moo 1.000001; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 6 | ▶ | use namespace::clean 0.25; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 6 | extends 'Term::CLI::Command'; | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | ▶ | has '+name' => ( default => sub {'help'} ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | has '+callback' => ( | ||||||||||||||||||||||||||||||||||||||||||
| 47 | default => sub { | ||||||||||||||||||||||||||||||||||||||||||
| 48 | sub { | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 6 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 6 | $self->_execute_help(@_); | |||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 6 | ); | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | ▶ | has '+options' => ( default => sub { [ 'pod|p', 'all|a' ] }, ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | has '+description' => ( | ||||||||||||||||||||||||||||||||||||||||||
| 58 | default => sub { | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 1 | ▶ | loc( qq{Show help for any given command sequence (or a command\n} | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | . qq{overview if no argument is given).\n\n} | ||||||||||||||||||||||||||||||||||||||||||
| 61 | . qq{The C<--pod> (C<-p>) option will cause raw POD\n} | ||||||||||||||||||||||||||||||||||||||||||
| 62 | . qq{to be shown.\n\n} | ||||||||||||||||||||||||||||||||||||||||||
| 63 | . qq{The C<--all> (C<-a>) option will list help text for all commands.} | ||||||||||||||||||||||||||||||||||||||||||
| 64 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 6 | ); | |||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | ▶ | has '+summary' => ( default => sub { loc('show help') }, ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | has '+_arguments' => ( | ||||||||||||||||||||||||||||||||||||||||||
| 71 | default => sub { | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | ▶ | [ Term::CLI::Argument::String->new( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | name => 'cmd', | ||||||||||||||||||||||||||||||||||||||||||
| 74 | min_occur => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 75 | max_occur => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 76 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 77 | ] | ||||||||||||||||||||||||||||||||||||||||||
| 78 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 6 | ); | |||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | sub _format_pod { | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | my ($self, $text) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_format_pod: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my $output; | |||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | my $parser = | |||||||||||||||||||||||||||||||||||||||||
| 87 | $POD_PARSER_CLASS->new( width => $self->term->term_width - 1 ); | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | $parser->output_string( \$output ); | |||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | $parser->parse_string_document($text); | |||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | return $output; | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | # ($pod, $text) = $self->_make_command_summary( %args ); | ||||||||||||||||||||||||||||||||||||||||||
| 95 | sub _make_command_summary { | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 3 | ▶ | my ( $self, %args ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_make_command_summary: called CC=4 SCAR=15.1
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 3 | my @cmd_path = map { $_->name } @{ $args{cmd_path} }; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 3 | my $commands = $args{commands}; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 3 | my $pod_prefix = $args{pod_prefix}; | |||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 3 | my $text = ''; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 3 | my $full_pod = ''; | |||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 3 | my $item_length = 0; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 3 | for my $cmd_ref (@$commands) { | |||||||||||||||||||||||||||||||||||||||||
| 107 | 12 | for my $usage ( $cmd_ref->usage_text( with_options => 'none' ) ) { | |||||||||||||||||||||||||||||||||||||||||
| 108 | 12 | my $item_text = join( ' ', ( map {"B<$_>"} @cmd_path ), $usage ); | |||||||||||||||||||||||||||||||||||||||||
| 109 | 12 | $full_pod .= "=item $item_text\n\n"; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 12 | my $l = length( $item_text =~ s/[BCEIL] < ([^>]*) >/$1/grx ); | |||||||||||||||||||||||||||||||||||||||||
| 111 | 12 | ▶ | $item_length = $l if $l > $item_length; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 12 | $full_pod .= $cmd_ref->summary; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 12 | $full_pod =~ s/\n*$/\n\n/sx; | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 3 | my $max_over_width = int( ( $self->term->term_width - 4 ) / 2 ); | |||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | my $over_width = min( $item_length + 4, $max_over_width ); | |||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | $full_pod = $pod_prefix . "=over $over_width\n\n$full_pod"; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | $full_pod .= "=back\n\n"; | |||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | # Format POD to text, remove extraneous empty lines. | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | $text = $self->_format_pod($full_pod); | |||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | $text =~ s/\n\n+/\n/gxs; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | $text =~ s/^\n+//x; | |||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | return ( $full_pod, $text ); | |||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | sub _get_help { | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 5 | ▶ | my ( $self, %args ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_help: called CC=7 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | # Handle "--all" in a separate routine. | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 5 | ▶ | if ( $args{options}->{all} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | return $self->_get_all_help(%args); | |||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | # Top-level help, i.e. "help" without arguments. | ||||||||||||||||||||||||||||||||||||||||||
| 140 | # Produce a simple command summary. | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 5 | ▶ | if ( @{ $args{arguments} } == 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 3 | my ( $pod, $text ) = $self->_make_command_summary( | |||||||||||||||||||||||||||||||||||||||||
| 143 | cmd_path => [], | ||||||||||||||||||||||||||||||||||||||||||
| 144 | pod_prefix => "=head2 " . loc("Commands") . ":\n\n", | ||||||||||||||||||||||||||||||||||||||||||
| 145 | commands => [ $self->parent->commands ] | ||||||||||||||||||||||||||||||||||||||||||
| 146 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | return ( %args, pod => $pod, text => $text ); | |||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | # We've been given arguments to "help". Find the | ||||||||||||||||||||||||||||||||||||||||||
| 151 | # appropriate command object, and work from there. | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 2 | my $cur_cmd_ref = $self->parent; | |||||||||||||||||||||||||||||||||||||||||
| 154 | 2 | my @cmd_ref_path; | |||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 2 | for my $cmd_name ( @{ $args{arguments} } ) { | |||||||||||||||||||||||||||||||||||||||||
| 157 | 3 | my $new_cmd_ref = $cur_cmd_ref->find_command($cmd_name); | |||||||||||||||||||||||||||||||||||||||||
| 158 | 3 | ▶ | if ( !$new_cmd_ref ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 2 | my @cmd_path = map { $_->name } @cmd_ref_path; | |||||||||||||||||||||||||||||||||||||||||
| 160 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 2 | ▶ | %args, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | status => -1, | ||||||||||||||||||||||||||||||||||||||||||
| 163 | error => @cmd_path > 0 | ||||||||||||||||||||||||||||||||||||||||||
| 164 | ? "@cmd_path: " . $cur_cmd_ref->error | ||||||||||||||||||||||||||||||||||||||||||
| 165 | : $cur_cmd_ref->error | ||||||||||||||||||||||||||||||||||||||||||
| 166 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 1 | push @cmd_ref_path, $new_cmd_ref; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 1 | $cur_cmd_ref = $new_cmd_ref; | |||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | my $pod = $self->_get_help_cmd( | |||||||||||||||||||||||||||||||||||||||||
| 173 | cmd_path => \@cmd_ref_path, | ||||||||||||||||||||||||||||||||||||||||||
| 174 | style => 'head1', | ||||||||||||||||||||||||||||||||||||||||||
| 175 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | $pod =~ s/\n*$/\n\n/sx; | |||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | my $pod2txt = $self->_format_pod($pod); | |||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | # Only list sub-commands if there are more than one. | ||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | if ( scalar( $cur_cmd_ref->commands ) > 1 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | my ( $cmd_pod, $cmd_text ) = $self->_make_command_summary( | |||||||||||||||||||||||||||||||||||||||||
| 184 | cmd_path => \@cmd_ref_path, | ||||||||||||||||||||||||||||||||||||||||||
| 185 | pod_prefix => "=head2 " . loc("Sub-Commands") . ":\n\n", | ||||||||||||||||||||||||||||||||||||||||||
| 186 | commands => [ $cur_cmd_ref->commands ], | ||||||||||||||||||||||||||||||||||||||||||
| 187 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | $pod .= $cmd_pod; | |||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | $pod2txt .= $cmd_text; | |||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | # Play fast and loose with the POD formatter output. | ||||||||||||||||||||||||||||||||||||||||||
| 193 | # Remove leading and trailing newlines. | ||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | $pod2txt =~ s/^\n+//sx; | |||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | $pod2txt =~ s/\n+$//sx; | |||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | return ( %args, pod => $pod, text => $pod2txt . "\n" ); | |||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | sub _get_help_cmd { | ||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | my ( $self, %args ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_help_cmd: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | my $style = $args{style} // 'item'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args{"style"} // "item"
MC/DC0%0/1
$args{"style"} // "item"
$args{"style"}
Truth table0%0/2
A
A= $args{"style"}
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | my @cmd_path = @{ $args{cmd_path} }; | |||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | my $cmd = $cmd_path[-1]; | |||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | my $usage_prefix = join( | ||||||||||||||||||||||||||||||||||||||||||
| 209 | ' ', | ||||||||||||||||||||||||||||||||||||||||||
| 210 | map { | ||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | $_->usage_text( with_options => 'none', with_subcommands => 0 ) | |||||||||||||||||||||||||||||||||||||||||
| 212 | } @cmd_path[ 0 .. $#cmd_path - 1 ] | ||||||||||||||||||||||||||||||||||||||||||
| 213 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | $usage_prefix .= ' ' if length $usage_prefix; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | my $pod; | |||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | if ( $style =~ /head/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | $pod .= "=$style " . loc("Usage") . ":\n\n"; | |||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | for my $usage ( $cmd->usage_text( with_options => 'both' ) ) { | |||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | $pod .= "=item " if $style eq 'item'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | $pod .= "$usage_prefix$usage\n\n"; | |||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | $pod =~ s/\n*$//sx; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | $pod .= "\n\n"; | |||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | my $description = ( $cmd->description || $cmd->summary ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$cmd->description || $cmd->summary
MC/DC0%0/2
$cmd->description || $cmd->summary
$cmd->description
$cmd->summary
Truth table0%0/3
A || B
A= $cmd->descriptionB= $cmd->summary
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | if ($description) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | $pod .= "=$style " . loc("Description") . ":\n\n" if $style =~ /head/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | $pod .= $description; | |||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | $pod =~ s/\n*$/\n\n/sx; | |||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | return $pod; | |||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | sub _get_help_all_commands { | ||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | my ( $self, %args ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_help_all_commands: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | my @cmd_path = @{ $args{cmd_path} // [] }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$args{"cmd_path"} // []
MC/DC0%0/1
$args{"cmd_path"} // []
$args{"cmd_path"}
Truth table0%0/2
A
A= $args{"cmd_path"}
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | my $cmd = $cmd_path[-1] // $self->parent; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$cmd_path[-1] // $self->parent
MC/DC0%0/2
$cmd_path[-1] // $self->parent
$cmd_path[-1]
$self->parent
Truth table0%0/3
A // B
A= $cmd_path[-1]B= $self->parent
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | my $pod = ''; | |||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | if ( $cmd->has_commands ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | for my $command ( $cmd->commands ) { | |||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | $pod .= $self->_get_help_all_commands( | |||||||||||||||||||||||||||||||||||||||||
| 253 | cmd_path => [ @cmd_path, $command ] ); | ||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | return $pod; | |||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | return $self->_get_help_cmd( cmd_path => \@cmd_path ); | |||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | sub _get_all_help { | ||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | my ( $self, %args ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_all_help: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | my ( $pod1, $txt1 ) = $self->_make_command_summary( | |||||||||||||||||||||||||||||||||||||||||
| 265 | cmd_path => [], | ||||||||||||||||||||||||||||||||||||||||||
| 266 | pod_prefix => "=head1 " . loc("COMMAND SUMMARY") . "\n\n", | ||||||||||||||||||||||||||||||||||||||||||
| 267 | commands => [ $self->parent->commands ] | ||||||||||||||||||||||||||||||||||||||||||
| 268 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | my $pod2 = | |||||||||||||||||||||||||||||||||||||||||
| 271 | "\n=head1 " | ||||||||||||||||||||||||||||||||||||||||||
| 272 | . loc("COMMANDS") . "\n\n" | ||||||||||||||||||||||||||||||||||||||||||
| 273 | . "=over\n\n" | ||||||||||||||||||||||||||||||||||||||||||
| 274 | . $self->_get_help_all_commands() | ||||||||||||||||||||||||||||||||||||||||||
| 275 | . "=back\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | my $txt2 = $self->_format_pod($pod2); | |||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | # Play fast and loose with the POD formatter output. | ||||||||||||||||||||||||||||||||||||||||||
| 280 | # Remove leading and trailing newlines. | ||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | $txt2 =~ s/^\n+//sx; | |||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | $txt2 =~ s/\n+$//sx; | |||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | $txt2 .= "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | return ( %args, pod => $pod1 . $pod2, text => "$txt1\n$txt2" ); | |||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | sub complete { | ||||||||||||||||||||||||||||||||||||||||||
| 289 | 7 | ▶ | my ( $self, $text, $state ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
complete: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | 7 | ▶ | my $processed = $state->{processed} //= []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$state->{"processed"} //= []
MC/DC0%0/1
$state->{"processed"} //= []
$state->{"processed"}
Truth table50%1/2
A
A= $state->{"processed"}
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | 7 | ▶ | my $unprocessed = $state->{unprocessed} //= []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$state->{"unprocessed"} //= []
MC/DC0%0/1
$state->{"unprocessed"} //= []
$state->{"unprocessed"}
Truth table50%1/2
A
A= $state->{"unprocessed"}
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | 7 | ▶ | my $parsed_options = $state->{options} //= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$state->{"options"} //= {}
MC/DC0%0/1
$state->{"options"} //= {}
$state->{"options"}
Truth table50%1/2
A
A= $state->{"options"}
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | # uncoverable branch false | ||||||||||||||||||||||||||||||||||||||||||
| 296 | 7 | ▶ | if ( $self->has_options ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | 7 | Getopt::Long::Configure(qw(bundling require_order pass_through)); | |||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | 7 | my %opt_result = get_options_from_array( | |||||||||||||||||||||||||||||||||||||||||
| 301 | args => $unprocessed, | ||||||||||||||||||||||||||||||||||||||||||
| 302 | spec => $self->options, | ||||||||||||||||||||||||||||||||||||||||||
| 303 | result => $parsed_options, | ||||||||||||||||||||||||||||||||||||||||||
| 304 | pass_through => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 305 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | 7 | my $double_dash = $opt_result{double_dash}; | |||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | 7 | ▶ | if ( !$double_dash && @{$unprocessed} == 0 && $text =~ /^-/x ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
not $double_dash and @{$unprocessed;} == 0 and $text =~ /^-/ux
not $double_dash and @{$unprocessed;} == 0
MC/DC100%3/3
not $double_dash and @{$unprocessed;} == 0 and $text =~ /^-/ux
not $double_dash
@{$unprocessed;} == 0
$text =~ /^-/ux
Truth table100%4/4
not(A) and B and C
A= not $double_dashB= @{$unprocessed;} == 0C= $text =~ /^-/ux
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | # We have to complete a command-line option. | ||||||||||||||||||||||||||||||||||||||||||
| 312 | 1 | return grep { is_prefix_str( $text, $_ ) } $self->option_names; | |||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | 6 | my $cur_cmd_ref = $self->parent; | |||||||||||||||||||||||||||||||||||||||||
| 317 | 6 | ▶ | while (@$unprocessed) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 4 | my $new_cmd_ref = $cur_cmd_ref->find_command( $unprocessed->[0] ); | |||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | 4 | ▶ | return () if !$new_cmd_ref; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | 3 | push @{$processed}, { | |||||||||||||||||||||||||||||||||||||||||
| 323 | element => $new_cmd_ref, | ||||||||||||||||||||||||||||||||||||||||||
| 324 | 3 | value => shift @{$unprocessed}, | |||||||||||||||||||||||||||||||||||||||||
| 325 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 326 | 3 | $cur_cmd_ref = $new_cmd_ref; | |||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | 5 | ▶ | return grep { is_prefix_str( $text, $_ ) } $cur_cmd_ref->command_names | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | if $cur_cmd_ref->has_commands; | ||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | 1 | return (); | |||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | # %args = HELP->_execute_help(%args); | ||||||||||||||||||||||||||||||||||||||||||
| 336 | # | ||||||||||||||||||||||||||||||||||||||||||
| 337 | # Callback for the builtin "help" command. | ||||||||||||||||||||||||||||||||||||||||||
| 338 | # | ||||||||||||||||||||||||||||||||||||||||||
| 339 | sub _execute_help { | ||||||||||||||||||||||||||||||||||||||||||
| 340 | 6 | ▶ | my ( $self, %args ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_execute_help: called CC=7 SCAR=32.9
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | 6 | ▶ | return %args if $args{status} < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | 5 | %args = $self->_get_help(%args); | |||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | 2 | ▶ | return %args if $args{status} < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | if ( $args{options}->{pod} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | print "\n$args{pod}"; | |||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | return %args; | |||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | my $cli = $self->root_node; | |||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | ▶ | if ( $cli->can('write_pager') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | return $cli->write_pager(%args); | |||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | my $ok = print $args{text}, $args{text} =~ /\n$/xms ? '' : "\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | if (!$ok) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | $args{status} = -1; | |||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | $args{error} = $!; | |||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | return %args; | |||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | __END__ | ||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||
| 371 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||
| 373 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||
| 375 | Term::CLI::Command::Help - A generic 'help' command for Term::CLI | ||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||
| 377 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | version 0.061000 | ||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||
| 381 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||
| 383 | use Term::CLI; | ||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||
| 385 | my $cli = Term::CLI->new( | ||||||||||||||||||||||||||||||||||||||||||
| 386 | name => 'myapp', | ||||||||||||||||||||||||||||||||||||||||||
| 387 | prompt => 'myapp> ', | ||||||||||||||||||||||||||||||||||||||||||
| 388 | commands => [ | ||||||||||||||||||||||||||||||||||||||||||
| 389 | Term::CLI::Command::Help->new(), | ||||||||||||||||||||||||||||||||||||||||||
| 390 | Term::CLI::Command->new( name => 'copy', ... ), | ||||||||||||||||||||||||||||||||||||||||||
| 391 | Term::CLI::Command->new( name => 'move', ... ), | ||||||||||||||||||||||||||||||||||||||||||
| 392 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 393 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | $cli->execute('help'); | ||||||||||||||||||||||||||||||||||||||||||
| 396 | # -> command summary | ||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | say "\n----\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | $cli->execute('help copy'); | ||||||||||||||||||||||||||||||||||||||||||
| 401 | # -> detailed help on 'copy'. | ||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||
| 403 | (See L<EXAMPLE|/EXAMPLE> for a working example.) | ||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | The C<Term::CLI::Command::Help> class is derived from | ||||||||||||||||||||||||||||||||||||||||||
| 408 | L<Term::CLI::Command>(3p) and implements | ||||||||||||||||||||||||||||||||||||||||||
| 409 | a generic "help" command for L<Term::CLI>(3p) applications. | ||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | The C<help> command accepts arguments that it will try to match against | ||||||||||||||||||||||||||||||||||||||||||
| 412 | the commands of its L<Term::CLI>(3p) parent. | ||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||
| 414 | It supports completion, as well as a C<--pod> option to dump raw POD text, | ||||||||||||||||||||||||||||||||||||||||||
| 415 | and a C<--all> option to show a command summary followed by extended | ||||||||||||||||||||||||||||||||||||||||||
| 416 | help on each commands. | ||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||
| 418 | =head1 CONSTRUCTORS | ||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||
| 422 | =item B<new> | ||||||||||||||||||||||||||||||||||||||||||
| 423 | X<new> | ||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||
| 425 | Create a new C<Term::CLI::Command::Help> object and return a reference | ||||||||||||||||||||||||||||||||||||||||||
| 426 | to it. | ||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||
| 428 | The object provides appropriate default values for all attributes, | ||||||||||||||||||||||||||||||||||||||||||
| 429 | so there is no need to provide any. | ||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||
| 431 | If you want, you can override the default attributes; in that case, | ||||||||||||||||||||||||||||||||||||||||||
| 432 | see the L<Term::CLI::Command>(3p) documentation. Attributes that are | ||||||||||||||||||||||||||||||||||||||||||
| 433 | "safe" to override are: | ||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||
| 435 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||
| 437 | =item B<description> =E<gt> I<Str> | ||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | Override the default description for the C<help> command. | ||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||
| 441 | =item B<name> =E<gt> I<Str> | ||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||
| 443 | Override the name for the help command. Default is C<help>. | ||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||
| 445 | =item B<summary> =E<gt> | ||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||
| 447 | Override the default summary for the C<help> command. | ||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||
| 449 | =item B<usage> =E<gt> | ||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||
| 451 | Override the automatic usage string for the C<help> command. | ||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||
| 455 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | =head1 OUTPUT FORMATTING | ||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||
| 459 | Help text is assumed to be in L<POD|perlpod> format, and will be formatted | ||||||||||||||||||||||||||||||||||||||||||
| 460 | for the terminal using L<Pod::Text::Termcap>(3p). | ||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||
| 462 | =head1 OUTPUT PAGING | ||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||
| 464 | The C<help> command will use the parent L<Term::CLI|Term::CLI>(3p)'s | ||||||||||||||||||||||||||||||||||||||||||
| 465 | L<write_pager()|Term::CLI/write_pager> method to pipe the formatted output | ||||||||||||||||||||||||||||||||||||||||||
| 466 | through a suitable pager. | ||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||
| 468 | =head1 EXAMPLE | ||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||
| 470 | Using the following code: | ||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||
| 472 | use Term::CLI; | ||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||
| 474 | my $cli = Term::CLI->new( | ||||||||||||||||||||||||||||||||||||||||||
| 475 | name => 'myapp', | ||||||||||||||||||||||||||||||||||||||||||
| 476 | prompt => 'myapp> ', | ||||||||||||||||||||||||||||||||||||||||||
| 477 | commands => [ | ||||||||||||||||||||||||||||||||||||||||||
| 478 | Term::CLI::Command::Help->new(), | ||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||
| 480 | Term::CLI::Command->new( | ||||||||||||||||||||||||||||||||||||||||||
| 481 | name => 'copy', | ||||||||||||||||||||||||||||||||||||||||||
| 482 | options => [ 'verbose!' ], | ||||||||||||||||||||||||||||||||||||||||||
| 483 | summary => 'copy I<src> to I<dst>', | ||||||||||||||||||||||||||||||||||||||||||
| 484 | description => | ||||||||||||||||||||||||||||||||||||||||||
| 485 | qq{Copy I<src> to I<dst>.\n} | ||||||||||||||||||||||||||||||||||||||||||
| 486 | .qq{Show progress if C<--verbose> is given.}, | ||||||||||||||||||||||||||||||||||||||||||
| 487 | arguments => [ | ||||||||||||||||||||||||||||||||||||||||||
| 488 | Term::CLI::Argument::Filename->new(name => 'src'), | ||||||||||||||||||||||||||||||||||||||||||
| 489 | Term::CLI::Argument::Filename->new(name => 'dst'), | ||||||||||||||||||||||||||||||||||||||||||
| 490 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 491 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 492 | Term::CLI::Command->new( | ||||||||||||||||||||||||||||||||||||||||||
| 493 | name => 'move', | ||||||||||||||||||||||||||||||||||||||||||
| 494 | options => [ 'verbose!' ], | ||||||||||||||||||||||||||||||||||||||||||
| 495 | summary => 'move I<src> to I<dst>', | ||||||||||||||||||||||||||||||||||||||||||
| 496 | description => | ||||||||||||||||||||||||||||||||||||||||||
| 497 | qq{Move I<src> to I<dst>.\n} | ||||||||||||||||||||||||||||||||||||||||||
| 498 | .qq{Move progress if C<--verbose> is given.}, | ||||||||||||||||||||||||||||||||||||||||||
| 499 | arguments => [ | ||||||||||||||||||||||||||||||||||||||||||
| 500 | Term::CLI::Argument::Filename->new(name => 'src'), | ||||||||||||||||||||||||||||||||||||||||||
| 501 | Term::CLI::Argument::Filename->new(name => 'dst'), | ||||||||||||||||||||||||||||||||||||||||||
| 502 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 503 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 504 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 505 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||
| 507 | say "\n----\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||
| 509 | $cli->execute('help'); | ||||||||||||||||||||||||||||||||||||||||||
| 510 | # -> command summary | ||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||
| 512 | say "\n----\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||
| 514 | $cli->execute('help copy'); | ||||||||||||||||||||||||||||||||||||||||||
| 515 | # -> detailed help on 'copy'. | ||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||
| 517 | The output would look something like this: | ||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||
| 519 | ---- | ||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||
| 521 | Commands: | ||||||||||||||||||||||||||||||||||||||||||
| 522 | help [cmd ...] Show help. | ||||||||||||||||||||||||||||||||||||||||||
| 523 | copy src dst copy src to dst | ||||||||||||||||||||||||||||||||||||||||||
| 524 | move src dst move src to dst | ||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||
| 526 | ---- | ||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||
| 528 | Usage: | ||||||||||||||||||||||||||||||||||||||||||
| 529 | copy [--verbose] src dst | ||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||
| 531 | Description: | ||||||||||||||||||||||||||||||||||||||||||
| 532 | Copy src to dst. Show progress if "--verbose" is given. | ||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||
| 534 | ---- | ||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||
| 536 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||
| 538 | L<cat>(1), | ||||||||||||||||||||||||||||||||||||||||||
| 539 | L<less>(1), | ||||||||||||||||||||||||||||||||||||||||||
| 540 | L<more>(1), | ||||||||||||||||||||||||||||||||||||||||||
| 541 | L<perlpod>(1), | ||||||||||||||||||||||||||||||||||||||||||
| 542 | L<pg>(1), | ||||||||||||||||||||||||||||||||||||||||||
| 543 | L<Pod::Text::Termcap>(3p). | ||||||||||||||||||||||||||||||||||||||||||
| 544 | L<Term::CLI>(3p), | ||||||||||||||||||||||||||||||||||||||||||
| 545 | L<Term::CLI::Command>(3p). | ||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||
| 547 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||
| 549 | Steven Bakker E<lt>sbakker@cpan.orgE<gt>, 2018. | ||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||
| 551 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||
| 553 | Copyright (c) 2018 Steven Bakker | ||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||
| 555 | This module is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||
| 556 | it under the same terms as Perl itself. See "perldoc perlartistic." | ||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||
| 558 | This software is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||||||||||||||||
| 559 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||||||||||||||||
| 560 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||||
| 562 | =begin __PODCOVERAGE | ||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||
| 564 | =head1 THIS SECTION SHOULD BE HIDDEN | ||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||
| 566 | This section is meant for methods that should not be considered | ||||||||||||||||||||||||||||||||||||||||||
| 567 | for coverage. This typically includes things like BUILD and DEMOLISH from | ||||||||||||||||||||||||||||||||||||||||||
| 568 | Moo/Moose. It is possible to skip these when using the Pod::Coverage class | ||||||||||||||||||||||||||||||||||||||||||
| 569 | (using C<also_private>), but this is not an option when running C<cover> | ||||||||||||||||||||||||||||||||||||||||||
| 570 | from the command line. | ||||||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||||||
| 572 | The simplest trick is to add a hidden section with an item list containing | ||||||||||||||||||||||||||||||||||||||||||
| 573 | these methods. | ||||||||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||||||||
| 575 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||
| 577 | =item BUILD | ||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||
| 579 | =item DEMOLISH | ||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||
| 581 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||||||
| 583 | =end __PODCOVERAGE | ||||||||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||||||||
| 585 | =cut | ||||||||||||||||||||||||||||||||||||||||||