my ($proto, undef, @spec) = @$info;
my $cur = pop @argv;
my $re = defined($cur) ? qr/\A\Q$cur\E/ : qr/./;
- if (substr($cur // '-', 0, 1) eq '-') { # --switches
+ if (substr(my $_cur = $cur // '-', 0, 1) eq '-') { # --switches
# gross special case since the only git-config options
# Consider moving to a table if we need more special cases
# we use Getopt::Long for are the ones we reject, so these
}
map {
my $x = length > 1 ? "--$_" : "-$_";
- $x eq $cur ? () : $x;
+ $x eq $_cur ? () : $x;
} grep(!/_/, split(/\|/, $_, -1)) # help|h
} grep { $OPTDESC{"$_\t$cmd"} || $OPTDESC{$_} } @spec);
} elsif ($cmd eq 'config' && !@argv && !$CONFIG_KEYS{$cur}) {
my @v = ref($v) ? split(/\|/, $v->[0]) : ();
# get rid of ALL CAPS placeholder (e.g "OUT")
# (TODO: completion for external paths)
- shift(@v) if uc($v[0]) eq $v[0];
+ shift(@v) if scalar(@v) && uc($v[0]) eq $v[0];
@v;
} grep(/\A(?:[\w-]+\|)*$opt\b.*?(?:\t$cmd)?\z/, keys %OPTDESC);
}
$cmd =~ tr/-/_/;
if (my $sub = $self->can("_complete_$cmd")) {
- puts $self, $sub->($self, @argv, $cur);
+ puts $self, $sub->($self, @argv, $cur ? ($cur) : ());
}
# TODO: URLs, pathnames, OIDs, MIDs, etc... See optparse() for
# proto parsing.
# Maybe there's a better way to go about this in
# contrib/completion/lei-completion.bash
my $re = '';
- my $cur = pop @$argv;
+ my $cur = pop(@$argv) // '';
if (@$argv) {
my @x = @$argv;
if ($cur eq ':' && @x) {
my $end = ($pfx =~ s/([0-9\*]+)\z//) ? $1 : '';
my $x = delete($lei->{qterms}->{$pfx}) or next;
my $star = $end =~ tr/*//d ? '*' : '';
- my $min_len = ($end // 0) + 0;
+ my $min_len = ($end || 0) + 0;
# no wildcards for bool_pfx_external
$star = '' if $pfx =~ /\A(dfpre|dfpost|mid)\z/;
}
select(undef, undef, undef, $self->{delay});
} while (now < $end);
- croak "fcntl lock $self->{f}: $!";
+ die "fcntl lock timeout $self->{f}: $!\n";
}
sub acq_dotlock {
my ($self) = @_;
my $dot_lock = "$self->{f}.lock";
- my ($pfx, $base) = ($self->{f} =~ m!(\A.*?/)([^/]+)\z!);
+ my ($pfx, $base) = ($self->{f} =~ m!(\A.*?/)?([^/]+)\z!);
$pfx //= '';
my $pid = $$;
my $end = now + $self->{timeout};
croak "open $tmp (for $dot_lock): $!" if !$!{EXIST};
}
} while (now < $end);
- croak "dotlock $dot_lock";
+ die "dotlock timeout $dot_lock\n";
}
sub acq_flock {
return if flock($self->{fh}, $op);
select(undef, undef, undef, $self->{delay});
} while (now < $end);
- croak "flock $self->{f}: $!";
+ die "flock timeout $self->{f}: $!\n";
}
sub acq {
my $res = run_script(['lei', @$cmd], $env, $xopt // $lei_opt);
$err_skip and
$lei_err = join('', grep(!/$err_skip/, split(/^/m, $lei_err)));
+ if ($lei_err ne '') {
+ if ($lei_err =~ /Use of uninitialized/ ||
+ $lei_err =~ m!\bArgument .*? isn't numeric in !) {
+ fail "lei_err=$lei_err";
+ } else {
+ state $loud = $ENV{TEST_LEI_ERR_LOUD};
+ diag "lei_err=$lei_err" if $loud;
+ }
+ }
$res;
};