| 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
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
$args[0] and $args[0] =~ qr/^(?:-r|--root)$/
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)$/
| |||||||||||||||||||||||||||||
| 68 | 4 | ▶ | if ($args[0] =~ qr/^(?:--root=)$/) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
@args == 0 or not $args[0] =~ /^-/
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] =~ /^-/
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 12 | ▶ | my $command = $args[0] // ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
$args[0] // ""
MC/DC100%1/1
$args[0] // ""
$args[0]
Truth table100%2/2
A
A= $args[0]
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | /^(?:copy|new)$/ and do { @options = qw(--description --dryrun); last }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | /^edit$/ and do { @options = qw(--default --dryrun --properties -P); last }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | /^init$/ and do { @options = qw(--source); last }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | /^install$/ and do { @options = qw(--cpanm-exe --cpanm | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 100 | 0 | ▶ | /^nop$/ and do { @options = qw(--sleep); last }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | /^(?:un)?pin$/ and do { @options = qw(--dryrun --stack); last }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | /^(props|stacks)$/ and do { @options = qw(--format); last }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 0 | ▶ | /^pull$/ and do { @options = qw(--dryrun --norecurse --stack); last }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 12 | for ($command) { | |||||||||||||||||||||||||||
| 107 | 12 | ▶ | $_ eq $word and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||