line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: App::Spec Plugin for help subcommand and options |
2
|
4
|
|
|
4
|
|
1949
|
use strict; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
145
|
|
3
|
4
|
|
|
4
|
|
23
|
use warnings; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
193
|
|
4
|
|
|
|
|
|
|
package App::Spec::Plugin::Help; |
5
|
|
|
|
|
|
|
our $VERSION = '0.013'; # VERSION |
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
23
|
use Moo; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
32
|
|
8
|
|
|
|
|
|
|
with 'App::Spec::Role::Plugin::Subcommand'; |
9
|
|
|
|
|
|
|
with 'App::Spec::Role::Plugin::GlobalOptions'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $yaml; |
12
|
|
|
|
|
|
|
my $cmd = { |
13
|
|
|
|
|
|
|
name => 'help', |
14
|
|
|
|
|
|
|
summary => 'Show command help', |
15
|
|
|
|
|
|
|
class => 'App::Spec::Plugin::Help', |
16
|
|
|
|
|
|
|
op => 'cmd_help', |
17
|
|
|
|
|
|
|
subcommand_required => 0, |
18
|
|
|
|
|
|
|
options => [ |
19
|
|
|
|
|
|
|
{ spec => 'all' }, |
20
|
|
|
|
|
|
|
], |
21
|
|
|
|
|
|
|
}; |
22
|
|
|
|
|
|
|
my $options = [ |
23
|
|
|
|
|
|
|
{ |
24
|
|
|
|
|
|
|
name => 'help', |
25
|
|
|
|
|
|
|
summary => 'Show command help', |
26
|
|
|
|
|
|
|
type => 'flag', |
27
|
|
|
|
|
|
|
aliases => ['h'], |
28
|
|
|
|
|
|
|
}, |
29
|
|
|
|
|
|
|
]; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub install_subcommands { |
32
|
31
|
|
|
31
|
1
|
111
|
my ($class, %args) = @_; |
33
|
31
|
|
|
|
|
103
|
my $parent = $args{spec}; |
34
|
31
|
|
|
|
|
122
|
my $appspec = App::Spec::Subcommand->read($cmd); |
35
|
|
|
|
|
|
|
|
36
|
31
|
|
50
|
|
|
237
|
my $help_subcmds = $appspec->subcommands || {}; |
37
|
|
|
|
|
|
|
|
38
|
31
|
|
100
|
|
|
160
|
my $parent_subcmds = $parent->subcommands || {}; |
39
|
31
|
|
|
|
|
244
|
$class->_add_subcommands($help_subcmds, $parent_subcmds, { subcommand_required => 0 }); |
40
|
31
|
|
|
|
|
170
|
$appspec->subcommands($help_subcmds); |
41
|
|
|
|
|
|
|
|
42
|
31
|
|
|
|
|
122
|
return $appspec; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub cmd_help { |
46
|
4
|
|
|
4
|
1
|
14
|
my ($self, $run) = @_; |
47
|
4
|
|
|
|
|
13
|
my $spec = $run->spec; |
48
|
4
|
|
|
|
|
13
|
my $cmds = $run->commands; |
49
|
4
|
|
|
|
|
8
|
shift @$cmds; |
50
|
4
|
|
|
|
|
18
|
my $help = $spec->usage( |
51
|
|
|
|
|
|
|
commands => $cmds, |
52
|
|
|
|
|
|
|
colored => $run->colorize_code, |
53
|
|
|
|
|
|
|
); |
54
|
4
|
|
|
|
|
26
|
$run->out($help); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _add_subcommands { |
58
|
383
|
|
|
383
|
|
824
|
my ($self, $commands1, $commands2, $ref) = @_; |
59
|
383
|
50
|
|
|
|
556
|
for my $name (keys %{ $commands2 || {} }) { |
|
383
|
|
|
|
|
1598
|
|
60
|
352
|
50
|
|
|
|
737
|
next if $name eq "help"; |
61
|
352
|
|
|
|
|
623
|
my $cmd = $commands2->{ $name }; |
62
|
352
|
|
|
|
|
6066
|
$commands1->{ $name } = App::Spec::Subcommand->new( |
63
|
|
|
|
|
|
|
name => $name, |
64
|
|
|
|
|
|
|
subcommands => {}, |
65
|
|
|
|
|
|
|
%$ref, |
66
|
|
|
|
|
|
|
); |
67
|
352
|
|
100
|
|
|
2527
|
my $subcmds = $cmd->{subcommands} || {}; |
68
|
352
|
|
|
|
|
1071
|
$self->_add_subcommands($commands1->{ $name }->{subcommands}, $subcmds, $ref); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub install_options { |
73
|
31
|
|
|
31
|
1
|
116
|
my ($class, %args) = @_; |
74
|
31
|
|
|
|
|
111
|
return $options; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub init_run { |
78
|
30
|
|
|
30
|
1
|
109
|
my ($self, $run) = @_; |
79
|
30
|
|
|
|
|
191
|
$run->subscribe( |
80
|
|
|
|
|
|
|
global_options => { |
81
|
|
|
|
|
|
|
plugin => $self, |
82
|
|
|
|
|
|
|
method => "global_options", |
83
|
|
|
|
|
|
|
}, |
84
|
|
|
|
|
|
|
); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub global_options { |
88
|
32
|
|
|
32
|
1
|
143
|
my ($self, %args) = @_; |
89
|
32
|
|
|
|
|
80
|
my $run = $args{run}; |
90
|
32
|
|
|
|
|
93
|
my $options = $run->options; |
91
|
32
|
|
|
|
|
67
|
my $op; |
92
|
|
|
|
|
|
|
|
93
|
32
|
100
|
|
|
|
161
|
if ($run->spec->has_subcommands) { |
94
|
30
|
0
|
0
|
|
|
108
|
if ($options->{help} and (not @{ $run->argv } or $run->argv->[0] ne "help")) { |
|
|
|
33
|
|
|
|
|
95
|
|
|
|
|
|
|
# call subcommand 'help' |
96
|
0
|
|
|
|
|
0
|
unshift @{ $run->argv }, "help"; |
|
0
|
|
|
|
|
0
|
|
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
else { |
100
|
2
|
100
|
|
|
|
8
|
if ($options->{help}) { |
101
|
1
|
|
|
|
|
5
|
$op = "::cmd_help"; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
32
|
100
|
|
|
|
146
|
$run->op("App::Spec::Plugin::Help$op") if $op; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=pod |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 NAME |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
App::Spec::Plugin::Help - App::Spec Plugin for help subcommand and options |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 DESCRIPTION |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
This plugin is enabled in L by default. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
This is a plugin which adds C<-h|--help> options to your app. |
122
|
|
|
|
|
|
|
Also for apps with subcommands it adds a subcommand C. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
The help command can then be called with all existing subcommands, like this: |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
% app cmd1 |
127
|
|
|
|
|
|
|
% app cmd2 |
128
|
|
|
|
|
|
|
% app cmd2 cmd2a |
129
|
|
|
|
|
|
|
% app help |
130
|
|
|
|
|
|
|
% app help cmd1 |
131
|
|
|
|
|
|
|
% app help cmd2 |
132
|
|
|
|
|
|
|
% app help cmd2 cmd2a |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 METHODS |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=over 4 |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item cmd_help |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
This is the code which is executed when using C<-h|--help> or the subcommand |
141
|
|
|
|
|
|
|
help. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item install_options |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
This method is required by L. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
See L. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=item install_subcommands |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
This is required by L. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
See L. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item global_options |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
This method is called by L after global options have been read. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
For apps without subcommands it just sets the method to execute to |
160
|
|
|
|
|
|
|
L. |
161
|
|
|
|
|
|
|
No further processing is done. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
For apps with subcommands it inserts C at the beginning of the |
164
|
|
|
|
|
|
|
commandline arguments and continues processing. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=item init_run |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
See L |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=back |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=cut |
173
|
|
|
|
|
|
|
|