| 1 | package Bash::Completion::RequestX::Sqitch; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 1 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 1 | ▶ | use List::Util 'any'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | use Module::Pluggable | ||||||||||||||
| 6 | 1 | ▶ | require => 0, | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | inner => 0, | ||||||||||||||
| 8 | search_path => ['App::Sqitch::Command'], | ||||||||||||||
| 9 | 1 | sub_name => '_sqitch_commands'; | |||||||||||||
| 10 | 1 | ▶ | use Pg::ServiceFile; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 1 | ▶ | use Types::Standard qw/ArrayRef HasMethods Str/; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | |||||||||||||||
| 13 | # ABSTRACT: extended request class for Sqitch completion candidates | ||||||||||||||
| 14 | |||||||||||||||
| 15 | has args => ( | ||||||||||||||
| 16 | is => 'lazy', | ||||||||||||||
| 17 | isa => ArrayRef, | ||||||||||||||
| 18 | 9 | ▶ | builder => sub { | ||||||||||||
|
Subroutine
_build_args: called CC=1 SCAR=0.0
| |||||||||||||||
| 19 | 9 | [$_[0]->request->args] | |||||||||||||
| 20 | } | ||||||||||||||
| 21 | 1 | ); | |||||||||||||
| 22 | |||||||||||||||
| 23 | has command => ( | ||||||||||||||
| 24 | is => 'lazy', | ||||||||||||||
| 25 | isa => Str, | ||||||||||||||
| 26 | 9 | ▶ | builder => sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||
| 27 | 9 | ▶ | $_[0]->args->[0] // ''; | ||||||||||||
|
Condition100%2/2
$_[0]->args->[0] // ""
MC/DC100%1/1
$_[0]->args->[0] // ""
$_[0]->args->[0]
Truth table100%2/2
A
A= $_[0]->args->[0]
| |||||||||||||||
| 28 | } | ||||||||||||||
| 29 | 1 | ); | |||||||||||||
| 30 | |||||||||||||||
| 31 | # Ref['Bash::Completion::Request'] | ||||||||||||||
| 32 | 1 | has request => ( | |||||||||||||
| 33 | is => 'ro', | ||||||||||||||
| 34 | isa => HasMethods[qw/args word/], | ||||||||||||||
| 35 | required => 1, | ||||||||||||||
| 36 | ); | ||||||||||||||
| 37 | |||||||||||||||
| 38 | has pg_service_file => ( | ||||||||||||||
| 39 | is => 'lazy', | ||||||||||||||
| 40 | 0 | ▶ | builder => sub { Pg::ServiceFile->new() } | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 41 | 1 | ); | |||||||||||||
| 42 | |||||||||||||||
| 43 | has previous_arg => ( | ||||||||||||||
| 44 | is => 'lazy', | ||||||||||||||
| 45 | isa => Str, | ||||||||||||||
| 46 | 2 | ▶ | builder => sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||
| 47 | 2 | ▶ | shift->stripped_args->[-1] // '' | ||||||||||||
|
Condition100%2/2
+(shift())->stripped_args->[-1] // ""
MC/DC100%1/1
+(shift())->stripped_args->[-1] // ""
+(shift())->stripped_args->[-1]
Truth table100%2/2
A
A= +(shift())->stripped_args->[-1]
| |||||||||||||||
| 48 | } | ||||||||||||||
| 49 | 1 | ); | |||||||||||||
| 50 | |||||||||||||||
| 51 | has sqitch_commands => ( | ||||||||||||||
| 52 | is => 'lazy', | ||||||||||||||
| 53 | isa => ArrayRef, | ||||||||||||||
| 54 | 5 | ▶ | builder => sub { | ||||||||||||
|
Subroutine
_build_sqitch_commands: called CC=1 SCAR=2.6
| |||||||||||||||
| 55 | 0 | [map { m/(\w+)$/; $1 } shift->_sqitch_commands]; | |||||||||||||
| 56 | } | ||||||||||||||
| 57 | 1 | ); | |||||||||||||
| 58 | |||||||||||||||
| 59 | has sqitch_config => ( | ||||||||||||||
| 60 | is => 'lazy', | ||||||||||||||
| 61 | 0 | ▶ | builder => sub { | ||||||||||||
|
Subroutine
_build_sqitch_config: not called CC=1 SCAR=6.9
| |||||||||||||||
| 62 | 0 | require App::Sqitch::Config; | |||||||||||||
| 63 | 0 | return App::Sqitch::Config->new(); | |||||||||||||
| 64 | } | ||||||||||||||
| 65 | 1 | ); | |||||||||||||
| 66 | |||||||||||||||
| 67 | 1 | has sqitch_targets => ( | |||||||||||||
| 68 | is => 'lazy', | ||||||||||||||
| 69 | isa => ArrayRef, | ||||||||||||||
| 70 | ); | ||||||||||||||
| 71 | |||||||||||||||
| 72 | has stripped_args => ( | ||||||||||||||
| 73 | is => 'lazy', | ||||||||||||||
| 74 | isa => ArrayRef, | ||||||||||||||
| 75 | 6 | ▶ | builder => sub { | ||||||||||||
|
Subroutine
_build_stripped_args: called CC=3 SCAR=11.0
| |||||||||||||||
| 76 | 6 | my $self = shift; | |||||||||||||
| 77 | 6 | my $index = 0; | |||||||||||||
| 78 | 6 | ▶ | $index++ if $self->command; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 79 | 6 | ▶ | $index++ if $self->subcommand; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 80 | 6 | my @args = $self->request->args; | |||||||||||||
| 81 | 6 | return [splice(@args, $index)]; | |||||||||||||
| 82 | } | ||||||||||||||
| 83 | 1 | ); | |||||||||||||
| 84 | |||||||||||||||
| 85 | has subcommand => ( | ||||||||||||||
| 86 | is => 'lazy', | ||||||||||||||
| 87 | isa => Str, | ||||||||||||||
| 88 | 9 | ▶ | builder => sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||
| 89 | 9 | ▶ | $_[0]->args->[1] // '' | ||||||||||||
|
Condition100%2/2
$_[0]->args->[1] // ""
MC/DC100%1/1
$_[0]->args->[1] // ""
$_[0]->args->[1]
Truth table100%2/2
A
A= $_[0]->args->[1]
| |||||||||||||||
| 90 | } | ||||||||||||||
| 91 | 1 | ); | |||||||||||||
| 92 | |||||||||||||||
| 93 | 4 | ▶ | sub candidates { | ||||||||||||
|
Subroutine
candidates: called CC=4 SCAR=22.5
Pod
undocumented
| |||||||||||||||
| 94 | 4 | my $self = shift; | |||||||||||||
| 95 | |||||||||||||||
| 96 | # If this method is being called we know what the command is. Default the | ||||||||||||||
| 97 | # candidates to the available subcommands. | ||||||||||||||
| 98 | 4 | my $candidates = $self->sqitch_commands; | |||||||||||||
| 99 | |||||||||||||||
| 100 | 0 | ▶ | if (any { $_ eq $self->subcommand } @{$self->sqitch_commands}) { | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.6
Branch: 1 branch
| |||||||||||||||
| 101 | 0 | ▶ | if ($self->request->word =~ m/^db:/) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 102 | 0 | $candidates = [ map { "db:pg:///?service=$_" } | |||||||||||||
| 103 | 0 | @{ $self->pg_service_file->names } ]; | |||||||||||||
| 104 | } | ||||||||||||||
| 105 | elsif ($self->previous_arg eq '--target') { | ||||||||||||||
| 106 | 0 | $candidates = $self->sqitch_targets; | |||||||||||||
| 107 | } | ||||||||||||||
| 108 | else { | ||||||||||||||
| 109 | 0 | my $class = 'App::Sqitch::Command::' . $self->subcommand; | |||||||||||||
| 110 | 0 | eval "require $class"; | |||||||||||||
| 111 | |||||||||||||||
| 112 | # This could probably do with cleaning up. Several assumptions are | ||||||||||||||
| 113 | # made, including the options method existing on the class, and it | ||||||||||||||
| 114 | # returning an ARRAY. | ||||||||||||||
| 115 | # | ||||||||||||||
| 116 | # Additionally, this will return deprecated options and options | ||||||||||||||
| 117 | # that don't appear when viewing the command's help. | ||||||||||||||
| 118 | 0 | $candidates = _getopt_long_options([$class->options]); | |||||||||||||
| 119 | } | ||||||||||||||
| 120 | } | ||||||||||||||
| 121 | |||||||||||||||
| 122 | 4 | return _remove_list_from_list($candidates, $self->stripped_args); | |||||||||||||
| 123 | } | ||||||||||||||
| 124 | |||||||||||||||
| 125 | 0 | ▶ | sub _build_sqitch_targets { | ||||||||||||
|
Subroutine
_build_sqitch_targets: not called CC=3 SCAR=24.8
| |||||||||||||||
| 126 | 0 | my $self = shift; | |||||||||||||
| 127 | 0 | my $config = $self->sqitch_config; | |||||||||||||
| 128 | |||||||||||||||
| 129 | # Taken from App::Sqitch::Target (I don't understand Sqitch enough | ||||||||||||||
| 130 | # to know if this is good enough for --target at the moment). | ||||||||||||||
| 131 | 0 | my %dump = $config->dump; | |||||||||||||
| 132 | 0 | my %targets; | |||||||||||||
| 133 | 0 | for my $key (keys %dump) { | |||||||||||||
| 134 | 0 | ▶ | next if $key !~ /^target[.]([^.]+)[.]uri$/; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 135 | 0 | $targets{$1}++; | |||||||||||||
| 136 | } | ||||||||||||||
| 137 | |||||||||||||||
| 138 | 0 | return [sort keys %targets]; | |||||||||||||
| 139 | } | ||||||||||||||
| 140 | |||||||||||||||
| 141 | 0 | ▶ | sub _getopt_long_options { | ||||||||||||
|
Subroutine
_getopt_long_options: not called CC=2 SCAR=17.9
| |||||||||||||||
| 142 | 0 | my $getopts = shift; | |||||||||||||
| 143 | return [ | ||||||||||||||
| 144 | 0 | ▶ | map { my $first = ( split(qr/[|=!]/) )[0]; $first ? "--$first" : '' } | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 145 | @$getopts | ||||||||||||||
| 146 | ]; | ||||||||||||||
| 147 | } | ||||||||||||||
| 148 | |||||||||||||||
| 149 | 4 | ▶ | sub _remove_list_from_list { | ||||||||||||
|
Subroutine
_remove_list_from_list: called CC=1 SCAR=1.2
| |||||||||||||||
| 150 | 4 | my ($lista, $listb) = @_; | |||||||||||||
| 151 | 0 | ▶ | my $in = sub { any { $_ eq $_[0] } @$listb }; | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||
| 152 | 0 | return [grep { !$in->($_) } @$lista]; | |||||||||||||
| 153 | } | ||||||||||||||
| 154 | |||||||||||||||
| 155 | 1 | 1; | |||||||||||||