line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ============================================================================ |
2
|
|
|
|
|
|
|
package MooseX::App::Plugin::BashCompletion::Command; |
3
|
|
|
|
|
|
|
# ============================================================================ |
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
1149
|
use 5.010; |
|
4
|
|
|
|
|
16
|
|
6
|
4
|
|
|
4
|
|
22
|
use utf8; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
21
|
|
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
100
|
use namespace::autoclean; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
26
|
|
9
|
4
|
|
|
4
|
|
329
|
use Moose; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
31
|
|
10
|
4
|
|
|
4
|
|
29534
|
use MooseX::App::Command; |
|
4
|
|
|
|
|
14
|
|
|
4
|
|
|
|
|
21
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
command_short_description q(Bash completion automator); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub bash_completion { |
15
|
1
|
|
|
1
|
0
|
4
|
my ($self,$app) = @_; |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
|
|
2
|
my %command_map; |
18
|
1
|
|
|
|
|
4
|
my $app_meta = $app->meta; |
19
|
1
|
|
|
|
|
58
|
my $commands = $app_meta->app_commands; |
20
|
1
|
|
|
|
|
3
|
my @commands_to_complete = grep { $_ ne 'bash_completion' } sort keys %{$commands}; |
|
8
|
|
|
|
|
20
|
|
|
1
|
|
|
|
|
19
|
|
21
|
1
|
|
|
|
|
5
|
my $command_list = join (' ', @commands_to_complete); |
22
|
1
|
|
|
|
|
3
|
my $package = __PACKAGE__; |
23
|
1
|
|
|
|
|
53
|
my $prefix = $app_meta->app_base; |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
|
|
76
|
my ($sec,$min,$hour,$mday,$mon,$year) = localtime(time); |
26
|
1
|
|
|
|
|
6
|
$year += 1900; |
27
|
1
|
|
|
|
|
7
|
$mday = sprintf('%02i',$mday); |
28
|
1
|
|
|
|
|
4
|
$mon = sprintf('%02i',$mon+1); |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
4
|
$prefix =~ tr/./_/; |
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
|
|
4
|
foreach my $command (@commands_to_complete) { |
33
|
7
|
|
|
|
|
20
|
my $command_class = $commands->{$command}; |
34
|
7
|
|
|
|
|
32
|
Class::Load::load_class($command_class); |
35
|
|
|
|
|
|
|
#my @parameters = $app_meta->command_usage_attributes($command_class->meta,'parameter'); |
36
|
7
|
|
|
|
|
3962
|
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
|
|
|
|
|
30
|
options => [ map { $_->cmd_usage_name } @options ], |
|
34
|
|
|
|
|
101
|
|
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
1
|
|
|
|
|
4
|
my $syntax = ''; |
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
|
|
46
|
$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
|
|
|
|
|
13
|
foreach my $command (sort keys %command_map) { |
63
|
7
|
|
|
|
|
17
|
$syntax .= "_${prefix}_macc_${command}() {\n _${prefix}_compreply \""; |
64
|
|
|
|
|
|
|
#$syntax .= join(" ", @{$data->{parameters}}); |
65
|
7
|
|
|
|
|
12
|
$syntax .= join(" ", sort @{$command_map{$command}->{options}}); |
|
7
|
|
|
|
|
42
|
|
66
|
7
|
|
|
|
|
14
|
$syntax .= "\"\n}\n\n"; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
1
|
|
|
|
|
7
|
$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
|
|
|
|
|
49
|
$syntax .= "complete -o default -F _${prefix}_macc ". $app_meta->app_base. "\n"; |
90
|
|
|
|
|
|
|
|
91
|
1
|
|
|
|
|
46
|
return MooseX::App::Message::Envelope->new( |
92
|
|
|
|
|
|
|
MooseX::App::Message::Block->new({ body => $syntax }) |
93
|
|
|
|
|
|
|
); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
97
|
|
|
|
|
|
|
1; |