| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
9
|
|
|
9
|
|
5593
|
use strict; |
|
|
9
|
|
|
|
|
17
|
|
|
|
9
|
|
|
|
|
259
|
|
|
2
|
9
|
|
|
9
|
|
43
|
use warnings; |
|
|
9
|
|
|
|
|
15
|
|
|
|
9
|
|
|
|
|
330
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package App::Cmd::Command::commands 0.334; |
|
5
|
|
|
|
|
|
|
|
|
6
|
9
|
|
|
9
|
|
65
|
use App::Cmd::Command; |
|
|
9
|
|
|
|
|
16
|
|
|
|
9
|
|
|
|
|
327
|
|
|
7
|
9
|
|
|
9
|
|
4066
|
BEGIN { our @ISA = 'App::Cmd::Command' }; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: list the application's commands |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
#pod =head1 DESCRIPTION |
|
12
|
|
|
|
|
|
|
#pod |
|
13
|
|
|
|
|
|
|
#pod This command will list all of the application commands available and their |
|
14
|
|
|
|
|
|
|
#pod abstracts. |
|
15
|
|
|
|
|
|
|
#pod |
|
16
|
|
|
|
|
|
|
#pod =method execute |
|
17
|
|
|
|
|
|
|
#pod |
|
18
|
|
|
|
|
|
|
#pod This is the command's primary method and raison d'etre. It prints the |
|
19
|
|
|
|
|
|
|
#pod application's usage text (if any) followed by a sorted listing of the |
|
20
|
|
|
|
|
|
|
#pod application's commands and their abstracts. |
|
21
|
|
|
|
|
|
|
#pod |
|
22
|
|
|
|
|
|
|
#pod The commands are printed in sorted groups (created by C); each |
|
23
|
|
|
|
|
|
|
#pod group is set off by blank lines. |
|
24
|
|
|
|
|
|
|
#pod |
|
25
|
|
|
|
|
|
|
#pod =cut |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub execute { |
|
28
|
4
|
|
|
4
|
1
|
10
|
my ($self, $opt, $args) = @_; |
|
29
|
|
|
|
|
|
|
|
|
30
|
4
|
100
|
|
|
|
11
|
my $target = $opt->stderr ? *STDERR : *STDOUT; |
|
31
|
|
|
|
|
|
|
|
|
32
|
4
|
|
|
|
|
44
|
my @cmd_groups = $self->app->command_groups; |
|
33
|
4
|
0
|
|
|
|
10
|
my @primary_commands = map { @$_ if ref $_ } @cmd_groups; |
|
|
0
|
|
|
|
|
0
|
|
|
34
|
|
|
|
|
|
|
|
|
35
|
4
|
50
|
|
|
|
13
|
if (!@cmd_groups) { |
|
36
|
|
|
|
|
|
|
@primary_commands = |
|
37
|
32
|
100
|
|
|
|
85
|
grep { $_ ne 'version' or $self->app->{show_version} } |
|
38
|
4
|
|
|
|
|
12
|
map { ($_->command_names)[0] } |
|
|
32
|
|
|
|
|
206
|
|
|
39
|
|
|
|
|
|
|
$self->app->command_plugins; |
|
40
|
|
|
|
|
|
|
|
|
41
|
4
|
|
|
|
|
15
|
@cmd_groups = $self->sort_commands(@primary_commands); |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
4
|
|
|
|
|
7
|
my $fmt_width = 0; |
|
45
|
4
|
100
|
|
|
|
10
|
for (@primary_commands) { $fmt_width = length if length > $fmt_width } |
|
|
29
|
|
|
|
|
52
|
|
|
46
|
4
|
|
|
|
|
5
|
$fmt_width += 2; # pretty |
|
47
|
|
|
|
|
|
|
|
|
48
|
4
|
|
|
|
|
11
|
foreach my $cmd_set (@cmd_groups) { |
|
49
|
8
|
50
|
|
|
|
61
|
if (!ref $cmd_set) { |
|
50
|
0
|
|
|
|
|
0
|
print { $target } "$cmd_set:\n"; |
|
|
0
|
|
|
|
|
0
|
|
|
51
|
0
|
|
|
|
|
0
|
next; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
8
|
|
|
|
|
14
|
for my $command (@$cmd_set) { |
|
54
|
29
|
|
|
|
|
519
|
my $abstract = $self->app->plugin_for($command)->abstract; |
|
55
|
29
|
|
|
|
|
76
|
printf { $target } "%${fmt_width}s: %s\n", $command, $abstract; |
|
|
29
|
|
|
|
|
166
|
|
|
56
|
|
|
|
|
|
|
} |
|
57
|
8
|
|
|
|
|
176
|
print { $target } "\n"; |
|
|
8
|
|
|
|
|
23
|
|
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
#pod =method C |
|
62
|
|
|
|
|
|
|
#pod |
|
63
|
|
|
|
|
|
|
#pod my @sorted = $cmd->sort_commands(@unsorted); |
|
64
|
|
|
|
|
|
|
#pod |
|
65
|
|
|
|
|
|
|
#pod This method orders the list of commands into groups which it returns as a list of |
|
66
|
|
|
|
|
|
|
#pod arrayrefs, and optional group header strings. |
|
67
|
|
|
|
|
|
|
#pod |
|
68
|
|
|
|
|
|
|
#pod By default, the first group is for the "help" and "commands" commands, and all |
|
69
|
|
|
|
|
|
|
#pod other commands are in the second group. |
|
70
|
|
|
|
|
|
|
#pod |
|
71
|
|
|
|
|
|
|
#pod This method can be overridden by implementing the C method in |
|
72
|
|
|
|
|
|
|
#pod your application base clase. |
|
73
|
|
|
|
|
|
|
#pod |
|
74
|
|
|
|
|
|
|
#pod =cut |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub sort_commands { |
|
77
|
4
|
|
|
4
|
1
|
13
|
my ($self, @commands) = @_; |
|
78
|
|
|
|
|
|
|
|
|
79
|
4
|
|
|
|
|
17
|
my $float = qr/^(?:help|commands)$/; |
|
80
|
|
|
|
|
|
|
|
|
81
|
4
|
|
|
|
|
9
|
my @head = sort grep { $_ =~ $float } @commands; |
|
|
29
|
|
|
|
|
103
|
|
|
82
|
4
|
|
|
|
|
10
|
my @tail = sort grep { $_ !~ $float } @commands; |
|
|
29
|
|
|
|
|
89
|
|
|
83
|
|
|
|
|
|
|
|
|
84
|
4
|
|
|
|
|
19
|
return (\@head, \@tail); |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub opt_spec { |
|
88
|
|
|
|
|
|
|
return ( |
|
89
|
6
|
|
|
6
|
1
|
27
|
[ 'stderr' => 'hidden' ], |
|
90
|
|
|
|
|
|
|
); |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
__END__ |