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
|
|
5
|
use Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
5
|
1
|
|
|
1
|
|
6097
|
use 5.010; |
|
1
|
|
|
|
|
3
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.002'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use namespace::autoclean; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
13
|
|
9
|
1
|
|
|
1
|
|
53
|
use MooseX::App::Command; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
command_short_description q(Zsh completion automator); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub zsh_completion { |
14
|
1
|
|
|
1
|
1
|
2
|
my ($self,$app) = @_; |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
|
|
2
|
my %command_map; |
17
|
1
|
|
|
|
|
4
|
my $app_meta = $app->meta; |
18
|
1
|
|
|
|
|
57
|
my $commands = $app_meta->app_commands; |
19
|
1
|
|
|
|
|
9
|
my $command_list = join (' ', sort keys %{$commands}); |
|
1
|
|
|
|
|
6
|
|
20
|
1
|
|
|
|
|
3
|
my $package = __PACKAGE__; |
21
|
1
|
|
|
|
|
40
|
my $prefix = $app_meta->app_base; |
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
|
|
151
|
my ($sec,$min,$hour,$mday,$mon,$year) = localtime(time); |
24
|
1
|
|
|
|
|
4
|
$year += 1900; |
25
|
1
|
|
|
|
|
7
|
$mday = sprintf('%02i',$mday); |
26
|
1
|
|
|
|
|
4
|
$mon = sprintf('%02i',$mon+1); |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
|
|
4
|
$prefix =~ tr/./_/; |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
7
|
while (my ($command,$command_class) = each %$commands) { |
31
|
4
|
|
|
|
|
13
|
Class::Load::load_class($command_class); |
32
|
4
|
|
|
|
|
121
|
my @parameters = $app_meta->command_usage_attributes($command_class->meta,'parameter'); |
33
|
4
|
|
|
|
|
5307
|
my @options = $app_meta->command_usage_attributes($command_class->meta,[qw(option proto)]); |
34
|
4
|
|
|
|
|
5455
|
$command_map{$command} = { |
35
|
|
|
|
|
|
|
parameters => \@parameters, |
36
|
|
|
|
|
|
|
options => \@options, |
37
|
|
|
|
|
|
|
}; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
1
|
|
|
|
|
2
|
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
|
|
|
|
|
7
|
my $data = $command_map{ $command }; |
46
|
4
|
|
|
|
|
14
|
$subcmd .= <<"EOM"; |
47
|
|
|
|
|
|
|
$command) |
48
|
|
|
|
|
|
|
_${prefix}_$command |
49
|
|
|
|
|
|
|
;; |
50
|
|
|
|
|
|
|
EOM |
51
|
|
|
|
|
|
|
|
52
|
4
|
|
|
|
|
7
|
my $options = $command_map{ $command }->{options}; |
53
|
4
|
|
|
|
|
8
|
my $option_list = ''; |
54
|
4
|
|
|
|
|
6
|
my $parameter_list = ''; |
55
|
4
|
|
|
|
|
6
|
my $parameter_completion = ''; |
56
|
|
|
|
|
|
|
|
57
|
4
|
|
|
|
|
6
|
my $i = 2; |
58
|
4
|
|
|
|
|
5
|
for my $param (@{ $command_map{ $command }->{parameters} }) { |
|
4
|
|
|
|
|
13
|
|
59
|
4
|
|
|
|
|
53
|
my $name = $param->cmd_usage_name; |
60
|
4
|
|
|
|
|
469
|
my $doc = $param->documentation; |
61
|
|
|
|
|
|
|
|
62
|
4
|
|
|
|
|
22
|
my $comp = "_files"; |
63
|
4
|
50
|
|
|
|
141
|
if ($param->has_type_constraint) { |
64
|
4
|
|
|
|
|
126
|
my $tc = $param->type_constraint; |
65
|
4
|
100
|
|
|
|
32
|
if ($tc->isa('Moose::Meta::TypeConstraint::Enum')) { |
66
|
3
|
|
|
|
|
5
|
my $values = join ' ', sort @{ $tc->values }; |
|
3
|
|
|
|
|
105
|
|
67
|
3
|
|
|
|
|
25
|
$comp = "compadd -X '$doc' $values"; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
4
|
50
|
|
|
|
130
|
my $position = $param->is_required ? $i : '*'; |
71
|
4
|
|
|
|
|
28
|
$parameter_list .= qq{ '$position: :->$name' \\\n}; |
72
|
4
|
|
|
|
|
11
|
$parameter_completion .= <<"EOM"; |
73
|
|
|
|
|
|
|
$name) |
74
|
|
|
|
|
|
|
$comp |
75
|
|
|
|
|
|
|
;; |
76
|
|
|
|
|
|
|
EOM |
77
|
4
|
|
|
|
|
8
|
$i++; |
78
|
|
|
|
|
|
|
} |
79
|
4
|
100
|
|
|
|
13
|
if (length $parameter_completion) { |
80
|
2
|
|
|
|
|
6
|
$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
|
|
|
|
|
9
|
for my $opt (@$options) { |
90
|
10
|
|
|
|
|
31
|
my $name = $opt->cmd_usage_name; |
91
|
10
|
|
|
|
|
1781
|
my @names = $opt->cmd_name_possible; |
92
|
10
|
|
|
|
|
1529
|
my $doc = $opt->documentation; |
93
|
10
|
|
|
|
|
57
|
$doc =~ s/'/'"'"'/g; |
94
|
|
|
|
|
|
|
|
95
|
10
|
|
|
|
|
32
|
my @opt = split ' ', $name; |
96
|
10
|
100
|
|
|
|
23
|
if (@opt > 1) { |
97
|
|
|
|
|
|
|
# '(-q --quiet)'{-q,--quiet}'[Show minimal output]' \ |
98
|
4
|
|
|
|
|
6
|
$option_list .= " '(@{[ @opt ]})'\{@{[ join ',', @opt ]}\}'\[$doc\]"; |
|
4
|
|
|
|
|
17
|
|
|
4
|
|
|
|
|
18
|
|
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
else { |
101
|
6
|
|
|
|
|
18
|
$option_list .= " '$opt[0]\[$doc\]"; |
102
|
|
|
|
|
|
|
} |
103
|
10
|
50
|
|
|
|
384
|
if ($opt->has_type_constraint) { |
104
|
10
|
|
|
|
|
316
|
my $tc = $opt->type_constraint; |
105
|
10
|
100
|
|
|
|
335
|
if ($tc->isa('Moose::Meta::TypeConstraint::Enum')) { |
|
|
100
|
|
|
|
|
|
106
|
1
|
|
|
|
|
3
|
my $values = join ' ', sort @{ $tc->values }; |
|
1
|
|
|
|
|
39
|
|
107
|
1
|
|
|
|
|
84
|
$option_list .= ":$names[0]:($values)"; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
elsif ($opt->type_constraint->is_a_type_of('Bool')) { |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
else { |
112
|
3
|
|
|
|
|
1795
|
$option_list .= ":$names[0]"; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} |
115
|
10
|
|
|
|
|
733
|
$option_list .= "' \\\n"; |
116
|
|
|
|
|
|
|
} |
117
|
4
|
|
|
|
|
27
|
$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
|
|
|
|
|
27
|
$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
|
|
|
|
|
44
|
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 |