blib/lib/Bash/Completion/Plugins/pinto.pm

filter: Statementstmt 51.0% 50 / 98 Branchbran 50.0% 19 / 38 Conditioncond 100% 8 / 8 MC/DCmcdc 100% 5 / 5 Subroutinesub 70.0% 7 / 10 Podpod 100% 2 / 2 totaltotal 56.5% 91 / 161 CC 25 SCAR 42.9
CC
25
Cov
53%
complete
99.0
should_activate
2.0
_extract_stack
2.0
CRAP 73.2
↑ Summary
1 ## no critic (RequireUseStrict)
2 package Bash::Completion::Plugins::pinto;
3 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 $Bash::Completion::Plugins::pinto::AUTHORITY = 'cpan:SCHWIGON';
5 }
6 # ABSTRACT: Bash completion for pinto
7 2 $Bash::Completion::Plugins::pinto::VERSION = '0.004';
8 ## use critic (RequireUseStrict)
9 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use feature 'switch';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use parent 'Bash::Completion::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 ▶use Bash::Completion::Utils qw(command_in_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 my @pinto_commands = qw/commands help add copy
17 delete edit index init
18 install list manual merge
19 new nop pin props pull
20 stacks statistics unpin
21 verify version
22 /;
23  
24 2 my @pinto_options = qw/-h --help
25 -r --root
26 -q --quiet
27 -v --verbose
28 --nocolor
29 /;
30  
31 0 ▶sub should_activate {
Subroutine should_activate: not called CC=1 SCAR=6.9
Pod documented
32 0 return [ grep { command_in_path($_) } qw/pinto/ ];
33 }
34  
35 0 ▶sub _extract_stack {
Subroutine _extract_stack: not called CC=1 SCAR=6.9
36 0 my ( $stack ) = @_;
37  
38 #$stack =~ s/\@.*//;
39 0 return $stack;
40 }
41  
42 0 ▶sub _get_stacks {
Subroutine _get_stacks: not called CC=1 SCAR=6.9
43 0 my @stacks = split /\n/, qx(pinto stacks);
44 0 my ( $current_stack ) = grep { /^\*\s*/ } @stacks;
45 0 ( $current_stack ) = $current_stack =~ /^\*\s*(\S+)/;
46  
47 0 $current_stack = _extract_stack($current_stack);
48  
49 0 return ( $current_stack, map { /^\*?\s*(?<name>\S+)/; $+{'name'} } @stacks );
50 }
51  
52 12 ▶sub complete {
Subroutine complete: called CC=25 SCAR=46.0
Pod documented
53 12 my ( $self, $r ) = @_;
54  
55 12 my $word = $r->word;
56  
57 12 ▶ if ($word =~ /^-/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($word =~ /^-/) { } 0 12 12
58 0 $r->candidates(grep { /^\Q$word\E/ } @pinto_options);
59 } else {
60 12 my @args = $r->args;
61  
62 12 my @orig_args = @args;
63  
64 12 shift @args; # get rid of 'pinto'
65  
66 # get rid of (-rFOO|-r FOO|--root FOO|--root=FOO)
67 12 ▶ if ($args[0] and $args[0] =~ qr/^(?:-r|--root)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args[0] and $args[0] =~ qr/^(?:-r|--root)$/) 4 8 12
Condition100%3/3
$args[0] and $args[0] =~ qr/^(?:-r|--root)$/
!ll&&!rl&&r
174
MC/DC100%2/2
$args[0] and $args[0] =~ qr/^(?:-r|--root)$/
$args[0] $args[0] =~ qr/^(?:-r|--root)$/
Truth table100%3/3
A and B
A= $args[0]B= $args[0] =~ qr/^(?:-r|--root)$/
ABresult
0X0
100
111
68 4 ▶ if ($args[0] =~ qr/^(?:--root=)$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args[0] =~ qr/^(?:--root=)$/) { } 0 4 4
elsif ($args[1]) { } 4 0 4
69 0 shift @args;
70 } elsif ($args[1]) {
71 4 shift @args;
72 4 shift @args;
73 }
74 }
75  
76 12 ▶ shift @args until @args == 0 || $args[0] !~ /^-/;
Branch: 1 branch
BranchTrueFalseTotal
(@args == 0 or not $args[0] =~ /^-/) or do { shift @args } 12 2 14
Condition100%3/3
@args == 0 or not $args[0] =~ /^-/
l!l&&r!l&&!r
1112
MC/DC100%2/2
@args == 0 or not $args[0] =~ /^-/
@args == 0 not $args[0] =~ /^-/
Truth table100%3/3
A or not(B)
A= @args == 0B= not $args[0] =~ /^-/
ABresult
1X1
011
000
77  
78 12 ▶ my $command = $args[0] // '';
Condition100%2/2
$args[0] // ""
l!l
111
MC/DC100%1/1
$args[0] // ""
$args[0]
Truth table100%2/2
A
A= $args[0]
Aresult
11
00
79  
80 12 my @options = ();
81 12 for ($command) {
82 0 ▶ /^add$/ and do { @options = qw(--author --dryrun --norecurse --pin --stack); last };
Branch: 1 branch
BranchTrueFalseTotal
/^add$/ and do { @options = ("--author", "--dryrun", "--norecurse", "--pin", "--stack"); last } 0 12 12
83 0 ▶ /^(?:copy|new)$/ and do { @options = qw(--description --dryrun); last };
Branch: 1 branch
BranchTrueFalseTotal
/^(?:copy|new)$/ and do { @options = ("--description", "--dryrun"); last } 0 12 12
84 0 ▶ /^edit$/ and do { @options = qw(--default --dryrun --properties -P); last };
Branch: 1 branch
BranchTrueFalseTotal
/^edit$/ and do { @options = ("--default", "--dryrun", "--properties", "-P"); last } 0 12 12
85 0 ▶ /^init$/ and do { @options = qw(--source); last };
Branch: 1 branch
BranchTrueFalseTotal
/^init$/ and do { @options = "--source"; last } 0 12 12
86 0 ▶ /^install$/ and do { @options = qw(--cpanm-exe --cpanm
Branch: 1 branch
BranchTrueFalseTotal
/^install$/ and do { @options = ("--cpanm-exe", "--cpanm", "--cpanm-options", "-o", "-l", "--local-lib", "--local-lib-contained", "--pull", "--stack"); last } 0 12 12
87 --cpanm-options -o
88 -l --local-lib --local-lib-contained
89 --pull
90 --stack
91 0 ); last };
92 0 ▶ /^list$/ and do { @options = qw(--author -A
Branch: 1 branch
BranchTrueFalseTotal
/^list$/ and do { @options = ("--author", "-A", "--distributions", "-D", "--format", "--packages", "-P", "--pinned", "--stack", "-s"); last } 0 12 12
93 --distributions -D
94 --format
95 --packages -P
96 --pinned
97 --stack -s
98 0 ); last };
99 0 ▶ /^merge$/ and do { @options = qw(--dryrun); last };
Branch: 1 branch
BranchTrueFalseTotal
/^merge$/ and do { @options = "--dryrun"; last } 0 12 12
100 0 ▶ /^nop$/ and do { @options = qw(--sleep); last };
Branch: 1 branch
BranchTrueFalseTotal
/^nop$/ and do { @options = "--sleep"; last } 0 12 12
101 0 ▶ /^(?:un)?pin$/ and do { @options = qw(--dryrun --stack); last };
Branch: 1 branch
BranchTrueFalseTotal
/^(?:un)?pin$/ and do { @options = ("--dryrun", "--stack"); last } 0 12 12
102 0 ▶ /^(props|stacks)$/ and do { @options = qw(--format); last };
Branch: 1 branch
BranchTrueFalseTotal
/^(props|stacks)$/ and do { @options = "--format"; last } 0 12 12
103 0 ▶ /^pull$/ and do { @options = qw(--dryrun --norecurse --stack); last };
Branch: 1 branch
BranchTrueFalseTotal
/^pull$/ and do { @options = ("--dryrun", "--norecurse", "--stack"); last } 0 12 12
104 }
105  
106 12 for ($command) {
107 12 ▶ $_ eq $word and do {
Branch: 1 branch
BranchTrueFalseTotal
$_ eq $word and do { $r->candidates(grep({/^\Q$word\E/;} @pinto_commands, @pinto_options)); last } 12 0 12
108 12 $r->candidates(grep { /^\Q$word\E/ }
109 ( @pinto_commands, @pinto_options ));
110 12 last;
111 };
112 ##_get_stacks() is quite slow for my demanding taste (due to slow pinto startup time)
113 0 ▶ /^(?:copy|delete|index|list|merge|pin|unpin)$/ and do {
Branch: 1 branch
BranchTrueFalseTotal
/^(?:copy|delete|index|list|merge|pin|unpin)$/ and do { () = _get_stacks(); $r->candidates(grep({/^\Q$word\E/;} @options, @stacks)); last } 0 0 0
114 0 my ( $current_stack, @stacks ) = _get_stacks();
115 0 $r->candidates(grep { /^\Q$word\E/ } ( @options, @stacks ));
116 0 last;
117 };
118 0 ▶ /^(?:manual|help)$/ and do {
Branch: 1 branch
BranchTrueFalseTotal
/^(?:manual|help)$/ and do { $r->candidates(grep({/^\Q$word\E/;} @pinto_commands)); last } 0 0 0
119 0 $r->candidates(grep { /^\Q$word\E/ }
120 ( @pinto_commands ));
121 0 last;
122 };
123 # all other commands (including unrecognized ones) get
124 # no completions
125 0 $r->candidates(grep { /^\Q$word\E/ } ( @options ));
126 }
127 }
128 }
129  
130 2 1;
131  
132 __END__
↑ Summary