line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::App::Plugin::ZshCompletion::Command; |
2
|
|
|
|
|
|
|
# ABSTRACT: Command class for MooseX::App::Plugin::ZshCompletion |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
7
|
use Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
5
|
1
|
|
|
1
|
|
5898
|
use 5.010; |
|
1
|
|
|
|
|
4
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.003'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
7
|
use namespace::autoclean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
9
|
1
|
|
|
1
|
|
71
|
use MooseX::App::Command; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
command_short_description q(Zsh completion automator); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub zsh_completion { |
14
|
1
|
|
|
1
|
1
|
4
|
my ($self,$app) = @_; |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
|
|
2
|
my %command_map; |
17
|
1
|
|
|
|
|
4
|
my $app_meta = $app->meta; |
18
|
1
|
|
|
|
|
47
|
my $commands = $app_meta->app_commands; |
19
|
1
|
|
|
|
|
9
|
my $command_list = join (' ', sort keys %{$commands}); |
|
1
|
|
|
|
|
8
|
|
20
|
1
|
|
|
|
|
2
|
my $package = __PACKAGE__; |
21
|
1
|
|
|
|
|
28
|
my $prefix = $app_meta->app_base; |
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
|
|
75
|
my ($sec,$min,$hour,$mday,$mon,$year) = localtime(time); |
24
|
1
|
|
|
|
|
4
|
$year += 1900; |
25
|
1
|
|
|
|
|
8
|
$mday = sprintf('%02i',$mday); |
26
|
1
|
|
|
|
|
3
|
$mon = sprintf('%02i',$mon+1); |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
|
|
4
|
$prefix =~ tr/./_/; |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
7
|
while (my ($command,$command_class) = each %$commands) { |
31
|
4
|
|
|
|
|
16
|
Class::Load::load_class($command_class); |
32
|
4
|
|
|
|
|
130
|
my @parameters = $app_meta->command_usage_attributes($command_class->meta,'parameter'); |
33
|
4
|
|
|
|
|
5606
|
my @options = $app_meta->command_usage_attributes($command_class->meta,[qw(option proto)]); |
34
|
4
|
|
|
|
|
5485
|
$command_map{$command} = { |
35
|
|
|
|
|
|
|
parameters => \@parameters, |
36
|
|
|
|
|
|
|
options => \@options, |
37
|
|
|
|
|
|
|
}; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
1
|
|
|
|
|
3
|
my $syntax = ''; |
41
|
1
|
|
|
|
|
2
|
my $subcmd = ''; |
42
|
1
|
|
|
|
|
3
|
my $subcmd_functions = ''; |
43
|
|
|
|
|
|
|
|
44
|
1
|
|
|
|
|
6
|
for my $command (sort keys %command_map) { |
45
|
4
|
|
|
|
|
8
|
my $data = $command_map{ $command }; |
46
|
4
|
|
|
|
|
16
|
$subcmd .= <<"EOM"; |
47
|
|
|
|
|
|
|
$command) |
48
|
|
|
|
|
|
|
_${prefix}_$command |
49
|
|
|
|
|
|
|
;; |
50
|
|
|
|
|
|
|
EOM |
51
|
|
|
|
|
|
|
|
52
|
4
|
|
|
|
|
8
|
my $options = $command_map{ $command }->{options}; |
53
|
4
|
|
|
|
|
8
|
my $option_list = ''; |
54
|
4
|
|
|
|
|
7
|
my $parameter_list = ''; |
55
|
4
|
|
|
|
|
6
|
my $parameter_completion = ''; |
56
|
|
|
|
|
|
|
|
57
|
4
|
|
|
|
|
7
|
my $i = 2; |
58
|
4
|
|
|
|
|
6
|
for my $param (@{ $command_map{ $command }->{parameters} }) { |
|
4
|
|
|
|
|
11
|
|
59
|
4
|
|
|
|
|
13
|
my $name = $param->cmd_usage_name; |
60
|
4
|
|
|
|
|
383
|
my $doc = $param->documentation; |
61
|
|
|
|
|
|
|
|
62
|
4
|
|
|
|
|
24
|
my $comp = "_files"; |
63
|
4
|
50
|
|
|
|
115
|
if ($param->has_type_constraint) { |
64
|
4
|
|
|
|
|
114
|
my $tc = $param->type_constraint; |
65
|
4
|
100
|
|
|
|
32
|
if ($tc->isa('Moose::Meta::TypeConstraint::Enum')) { |
66
|
3
|
|
|
|
|
6
|
my $values = join ' ', sort @{ $tc->values }; |
|
3
|
|
|
|
|
75
|
|
67
|
3
|
|
|
|
|
26
|
$comp = "compadd -X '$doc' $values"; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
4
|
50
|
|
|
|
114
|
my $position = $param->is_required ? $i : '*'; |
71
|
4
|
|
|
|
|
33
|
$parameter_list .= qq{ '$position: :->$name' \\\n}; |
72
|
4
|
|
|
|
|
11
|
$parameter_completion .= <<"EOM"; |
73
|
|
|
|
|
|
|
$name) |
74
|
|
|
|
|
|
|
$comp |
75
|
|
|
|
|
|
|
;; |
76
|
|
|
|
|
|
|
EOM |
77
|
4
|
|
|
|
|
7
|
$i++; |
78
|
|
|
|
|
|
|
} |
79
|
4
|
100
|
|
|
|
11
|
if (length $parameter_completion) { |
80
|
2
|
|
|
|
|
8
|
$parameter_completion = <<"EOM"; |
81
|
|
|
|
|
|
|
curcontext="\${curcontext%:*:*}:$prefix-cmd-\$words[1]:" |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
case \$state in |
84
|
|
|
|
|
|
|
$parameter_completion |
85
|
|
|
|
|
|
|
esac |
86
|
|
|
|
|
|
|
EOM |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
4
|
|
|
|
|
10
|
for my $opt (@$options) { |
90
|
10
|
|
|
|
|
31
|
my $name = $opt->cmd_usage_name; |
91
|
10
|
|
|
|
|
2023
|
my @names = $opt->cmd_name_possible; |
92
|
10
|
|
|
|
|
1743
|
my $doc = $opt->documentation; |
93
|
10
|
|
|
|
|
64
|
$doc =~ s/'/'"'"'/g; |
94
|
|
|
|
|
|
|
|
95
|
10
|
|
|
|
|
26
|
my @opt = split ' ', $name; |
96
|
10
|
100
|
|
|
|
23
|
if (@opt > 1) { |
97
|
|
|
|
|
|
|
# '(-q --quiet)'{-q,--quiet}'[Show minimal output]' \ |
98
|
4
|
|
|
|
|
7
|
$option_list .= " '(@{[ @opt ]})'\{@{[ join ',', @opt ]}\}'\[$doc\]"; |
|
4
|
|
|
|
|
15
|
|
|
4
|
|
|
|
|
15
|
|
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
else { |
101
|
6
|
|
|
|
|
16
|
$option_list .= " '$opt[0]\[$doc\]"; |
102
|
|
|
|
|
|
|
} |
103
|
10
|
50
|
|
|
|
308
|
if ($opt->has_type_constraint) { |
104
|
10
|
|
|
|
|
316
|
my $tc = $opt->type_constraint; |
105
|
10
|
100
|
|
|
|
306
|
if ($tc->isa('Moose::Meta::TypeConstraint::Enum')) { |
|
|
100
|
|
|
|
|
|
106
|
1
|
|
|
|
|
2
|
my $values = join ' ', sort @{ $tc->values }; |
|
1
|
|
|
|
|
35
|
|
107
|
1
|
|
|
|
|
61
|
$option_list .= ":$names[0]:($values)"; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
elsif ($opt->type_constraint->is_a_type_of('Bool')) { |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
else { |
112
|
3
|
|
|
|
|
1514
|
$option_list .= ":$names[0]"; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} |
115
|
10
|
|
|
|
|
643
|
$option_list .= "' \\\n"; |
116
|
|
|
|
|
|
|
} |
117
|
4
|
|
|
|
|
38
|
$subcmd_functions .= <<"EOM"; |
118
|
|
|
|
|
|
|
_${prefix}_$command() { |
119
|
|
|
|
|
|
|
_arguments -C \\ |
120
|
|
|
|
|
|
|
'1: :->subcmd' \\ |
121
|
|
|
|
|
|
|
$parameter_list$option_list && ret=0 |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
$parameter_completion |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
EOM |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
1
|
|
|
|
|
26
|
$syntax .= <<"EOT"; |
130
|
|
|
|
|
|
|
#compdef $prefix |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# Built with $package on $year/$mon/$mday |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
_$prefix() { |
135
|
|
|
|
|
|
|
typeset -A opt_args |
136
|
|
|
|
|
|
|
local curcontext="\$curcontext" state line context |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
_arguments -s \\ |
139
|
|
|
|
|
|
|
'1: :->subcmd' \\ |
140
|
|
|
|
|
|
|
'*: :->args' \\ |
141
|
|
|
|
|
|
|
&& ret=0 |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
case \$state in |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
subcmd) |
146
|
|
|
|
|
|
|
compadd help $command_list |
147
|
|
|
|
|
|
|
;; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
args) |
150
|
|
|
|
|
|
|
curcontext="\${curcontext%:*:*}:$prefix-cmd-\$words[1]:" |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
case \$line[1] in |
153
|
|
|
|
|
|
|
$subcmd |
154
|
|
|
|
|
|
|
help) |
155
|
|
|
|
|
|
|
_${prefix}_help |
156
|
|
|
|
|
|
|
esac |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
esac |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
$subcmd_functions |
162
|
|
|
|
|
|
|
_${prefix}_help() { |
163
|
|
|
|
|
|
|
compadd $command_list |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
EOT |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
|
169
|
1
|
|
|
|
|
40
|
return MooseX::App::Message::Envelope->new( |
170
|
|
|
|
|
|
|
MooseX::App::Message::Block->new({ body => $syntax }) |
171
|
|
|
|
|
|
|
); |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
175
|
|
|
|
|
|
|
1; |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
__END__ |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 NAME |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
MooseX::App::Plugin::ZshCompletion::Command - generates the zsh completion for MooseX::App::Plugin::ZshCompletion |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 METHODS |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=over 4 |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=item zsh_completion |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
This method is doing the generation. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=back |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=cut |