line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OPM::Maker::Command::bashcompletion; |
2
|
|
|
|
|
|
|
$OPM::Maker::Command::bashcompletion::VERSION = '1.16'; |
3
|
16
|
|
|
16
|
|
16538
|
use strict; |
|
16
|
|
|
|
|
42
|
|
|
16
|
|
|
|
|
605
|
|
4
|
16
|
|
|
16
|
|
87
|
use warnings; |
|
16
|
|
|
|
|
32
|
|
|
16
|
|
|
|
|
516
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: build bash completion script |
7
|
|
|
|
|
|
|
|
8
|
16
|
|
|
16
|
|
85
|
use Carp qw(croak); |
|
16
|
|
|
|
|
41
|
|
|
16
|
|
|
|
|
907
|
|
9
|
16
|
|
|
16
|
|
2382
|
use Path::Class; |
|
16
|
|
|
|
|
169826
|
|
|
16
|
|
|
|
|
1053
|
|
10
|
|
|
|
|
|
|
|
11
|
16
|
|
|
16
|
|
144
|
use OPM::Maker -command; |
|
16
|
|
|
|
|
34
|
|
|
16
|
|
|
|
|
227
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub abstract { |
14
|
0
|
|
|
0
|
1
|
|
return "create bash completion script and enable it for the user"; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub opt_spec { |
18
|
0
|
|
|
0
|
1
|
|
return (); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub usage_desc { |
22
|
0
|
|
|
0
|
1
|
|
return "opmbuild bashcompletion"; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub execute { |
26
|
0
|
|
|
0
|
1
|
|
my ($self, $opt, $args) = @_; |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
my $app = $self->app; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my %commands = map { |
31
|
0
|
|
|
|
|
|
my ($short) = (split /::/, $_)[-1]; |
32
|
0
|
|
|
|
|
|
$short => $_; |
33
|
|
|
|
|
|
|
} grep { |
34
|
0
|
|
|
|
|
|
$_ =~ m{\AOPM::Maker::Command}; |
|
0
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
} $app->command_plugins; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
my %completion_data; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
CMD: |
40
|
0
|
|
|
|
|
|
for my $cmd ( sort keys %commands ) { |
41
|
0
|
|
|
|
|
|
my $module = $commands{$cmd}; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my @opts = map { |
44
|
0
|
|
0
|
|
|
|
my $opt_spec = $_->[0] // ''; |
|
0
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my $opt_name = ( split /=/, $opt_spec )[0]; |
46
|
0
|
0
|
|
|
|
|
$opt_name ? '--' . $opt_name : (); |
47
|
|
|
|
|
|
|
} $module->opt_spec; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
$completion_data{$cmd} = \@opts; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
my $bash_completion = $self->_bash_completion( %completion_data ); |
53
|
0
|
|
|
|
|
|
$self->_create_bash_completion_files( $bash_completion ); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub _create_bash_completion_files { |
57
|
0
|
|
|
0
|
|
|
my ($self, $content) = @_; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my $base = dir( $ENV{HOME} ); |
60
|
0
|
|
|
|
|
|
my $completion = $base->file( '.bash_completion' ); |
61
|
0
|
0
|
|
|
|
|
if ( !-f $completion->stringify ) { |
62
|
0
|
|
|
|
|
|
my $completion_content = q! |
63
|
|
|
|
|
|
|
for bcfile in ~/.bash_completion.d/* ; do |
64
|
|
|
|
|
|
|
. $bcfile |
65
|
|
|
|
|
|
|
done |
66
|
|
|
|
|
|
|
!; |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
$completion->spew( $completion_content ); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $dir = $base->subdir( '.bash_completion.d' ); |
72
|
0
|
0
|
|
|
|
|
if ( !-d $dir->stringify ) { |
73
|
0
|
|
|
|
|
|
$dir->mkpath; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
my $opmbuild_completion = $dir->file('opmbuild'); |
77
|
0
|
|
|
|
|
|
$opmbuild_completion->spew( $content ); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub _bash_completion { |
81
|
0
|
|
|
0
|
|
|
my ($self, %data) = @_; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
my $subcommands = join ' ', sort keys %data; |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
my @subcommand_data; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
CMD: |
88
|
0
|
|
|
|
|
|
for my $cmd ( sort keys %data ) { |
89
|
0
|
0
|
|
|
|
|
next CMD if !@{ $data{$cmd} || [] }; |
|
0
|
0
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my $case = sprintf q~ %s) |
92
|
|
|
|
|
|
|
local %s_opts="%s" |
93
|
|
|
|
|
|
|
COMPREPLY=( $(compgen -W "${%s_opts}" -- ${cur}) ) |
94
|
|
|
|
|
|
|
return 0 |
95
|
|
|
|
|
|
|
;;~, |
96
|
|
|
|
|
|
|
$cmd, |
97
|
|
|
|
|
|
|
$cmd, |
98
|
0
|
0
|
|
|
|
|
( join ' ', @{ $data{$cmd} || [] } ), |
|
0
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
$cmd |
100
|
|
|
|
|
|
|
; |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
push @subcommand_data, $case; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
my $subcommand_opts = join "\n", @subcommand_data; |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
my $completion_script = sprintf q~ |
108
|
|
|
|
|
|
|
_opmbuild() |
109
|
|
|
|
|
|
|
{ |
110
|
|
|
|
|
|
|
local cur prev opts base |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
COMPREPLY=() |
113
|
|
|
|
|
|
|
cur="${COMP_WORDS[COMP_CWORD]}" |
114
|
|
|
|
|
|
|
prev="${COMP_WORDS[COMP_CWORD-1]}" |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
opts="%s" |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
case "${prev}" in |
119
|
|
|
|
|
|
|
%s |
120
|
|
|
|
|
|
|
*) |
121
|
|
|
|
|
|
|
;; |
122
|
|
|
|
|
|
|
esac |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) |
125
|
|
|
|
|
|
|
return 0; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
complete -F _opmbuild opmbuild |
129
|
|
|
|
|
|
|
~, |
130
|
|
|
|
|
|
|
$subcommands, |
131
|
|
|
|
|
|
|
$subcommand_opts |
132
|
|
|
|
|
|
|
; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
1; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
__END__ |