line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ============================================================================ |
2
|
|
|
|
|
|
|
package MooseX::App::Plugin::BashCompletion::Command; |
3
|
|
|
|
|
|
|
# ============================================================================ |
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
1040
|
use 5.010; |
|
4
|
|
|
|
|
16
|
|
6
|
4
|
|
|
4
|
|
23
|
use utf8; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
22
|
|
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
100
|
use namespace::autoclean; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
22
|
|
9
|
4
|
|
|
4
|
|
299
|
use Moose; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
26
|
|
10
|
4
|
|
|
4
|
|
29618
|
use MooseX::App::Command; |
|
4
|
|
|
|
|
14
|
|
|
4
|
|
|
|
|
19
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
command_short_description q(Bash completion automator); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub bash_completion { |
15
|
1
|
|
|
1
|
0
|
3
|
my ($self,$app) = @_; |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
|
|
2
|
my %command_map; |
18
|
1
|
|
|
|
|
5
|
my $app_meta = $app->meta; |
19
|
1
|
|
|
|
|
63
|
my $commands = $app_meta->app_commands; |
20
|
1
|
|
|
|
|
3
|
my @commands_to_complete = grep { $_ ne 'bash_completion' } sort keys %{$commands}; |
|
8
|
|
|
|
|
17
|
|
|
1
|
|
|
|
|
7
|
|
21
|
1
|
|
|
|
|
6
|
my $command_list = join (' ', @commands_to_complete); |
22
|
1
|
|
|
|
|
3
|
my $package = __PACKAGE__; |
23
|
1
|
|
|
|
|
48
|
my $prefix = $app_meta->app_base; |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
|
|
43
|
my ($sec,$min,$hour,$mday,$mon,$year) = localtime(time); |
26
|
1
|
|
|
|
|
5
|
$year += 1900; |
27
|
1
|
|
|
|
|
6
|
$mday = sprintf('%02i',$mday); |
28
|
1
|
|
|
|
|
4
|
$mon = sprintf('%02i',$mon+1); |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
3
|
$prefix =~ tr/./_/; |
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
|
|
4
|
foreach my $command (@commands_to_complete) { |
33
|
7
|
|
|
|
|
23
|
my $command_class = $commands->{$command}; |
34
|
7
|
|
|
|
|
28
|
Class::Load::load_class($command_class); |
35
|
|
|
|
|
|
|
#my @parameters = $app_meta->command_usage_attributes($command_class->meta,'parameter'); |
36
|
7
|
|
|
|
|
3858
|
my @options = $app_meta->command_usage_attributes($command_class->meta,[qw(option proto)]); |
37
|
|
|
|
|
|
|
$command_map{$command} = { |
38
|
|
|
|
|
|
|
#parameters => [ map { $_->is_required } @parameters ], |
39
|
7
|
|
|
|
|
28
|
options => [ map { $_->cmd_usage_name } @options ], |
|
34
|
|
|
|
|
94
|
|
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
1
|
|
|
|
|
4
|
my $syntax = ''; |
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
|
|
10
|
$syntax .= <<"EOT"; |
46
|
|
|
|
|
|
|
#!/bin/bash |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Built with $package on $year/$mon/$mday |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
${prefix}_COMMANDS='help $command_list' |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
_${prefix}_macc_help() { |
53
|
|
|
|
|
|
|
if [ \$COMP_CWORD = 2 ]; then |
54
|
|
|
|
|
|
|
_${prefix}_compreply "\$${prefix}_COMMANDS" |
55
|
|
|
|
|
|
|
else |
56
|
|
|
|
|
|
|
COMPREPLY=() |
57
|
|
|
|
|
|
|
fi |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
EOT |
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
9
|
foreach my $command (sort keys %command_map) { |
63
|
7
|
|
|
|
|
21
|
$syntax .= "_${prefix}_macc_${command}() {\n _${prefix}_compreply \""; |
64
|
|
|
|
|
|
|
#$syntax .= join(" ", @{$data->{parameters}}); |
65
|
7
|
|
|
|
|
9
|
$syntax .= join(" ", @{$command_map{$command}->{options}}); |
|
7
|
|
|
|
|
38
|
|
66
|
7
|
|
|
|
|
13
|
$syntax .= "\"\n}\n\n"; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
1
|
|
|
|
|
9
|
$syntax .= <<"EOT"; |
70
|
|
|
|
|
|
|
_${prefix}_compreply() { |
71
|
|
|
|
|
|
|
COMPREPLY=(\$(compgen -W "\$1" -- \${COMP_WORDS[COMP_CWORD]})) |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
_${prefix}_macc() { |
75
|
|
|
|
|
|
|
case \$COMP_CWORD in |
76
|
|
|
|
|
|
|
0) |
77
|
|
|
|
|
|
|
;; |
78
|
|
|
|
|
|
|
1) |
79
|
|
|
|
|
|
|
_${prefix}_compreply "\$${prefix}_COMMANDS" |
80
|
|
|
|
|
|
|
;; |
81
|
|
|
|
|
|
|
*) |
82
|
|
|
|
|
|
|
eval _${prefix}_macc_\${COMP_WORDS[1]} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
esac |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
EOT |
88
|
|
|
|
|
|
|
|
89
|
1
|
|
|
|
|
40
|
$syntax .= "complete -o default -F _${prefix}_macc ". $app_meta->app_base. "\n"; |
90
|
|
|
|
|
|
|
|
91
|
1
|
|
|
|
|
40
|
return MooseX::App::Message::Envelope->new( |
92
|
|
|
|
|
|
|
MooseX::App::Message::Block->new({ body => $syntax }) |
93
|
|
|
|
|
|
|
); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
97
|
|
|
|
|
|
|
1; |