File: Help.pm

package info (click to toggle)
libcli-framework-perl 0.05-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 456 kB
  • sloc: perl: 2,168; sql: 18; sh: 3; makefile: 2
file content (61 lines) | stat: -rw-r--r-- 1,495 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package CLI::Framework::Command::Help;
use base qw( CLI::Framework::Command::Meta );

use strict;
use warnings;

our $VERSION = 0.01;

#-------

sub usage_text {
    q{
    help [command name]: usage information for an individual command or the application itself
    }
}

sub run {
    my ($self, $opts, @args) = @_;

    my $app = $self->get_app(); # metacommand is app-aware

    my $usage;
    my $command_name = shift @args;

    # Recognize help requests that refer to the target command by an alias...
    my %alias = $app->command_alias();
    $command_name = $alias{$command_name} if $command_name && exists $alias{$command_name};

    # First, attempt to get command-specific usage message...
    if( $command_name ) {
        # (do not show command-specific usage message for non-interactive
        # commands when in interactive mode)
        $usage = $app->usage( $command_name, @args )
            unless( $app->get_interactivity_mode() && ! $app->is_interactive_command($command_name) );
    }
    # Fall back to application usage message...
    $usage ||= $app->usage();
    return $usage;
}

#-------
1;

__END__

=pod

=head1 NAME

CLI::Framework::Command::Help - CLIF built-in command to print application or
command-specific usage messages

=head1 SEE ALSO

L<Command usage()|CLI::Framework::Command/usage( $subcommand_name, @subcommand_chain )>

L<Application usage()|CLI::Framework::Application/usage( $command_name, @subcommand_chain )>

L<CLI::Framework::Command>

=cut