Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

61 lines (43 sloc) 1.475 kb
# This option sanity-checking causes me too much pain with .ackrc files,
# but I don't want to throw away what I have.
#
# Some day I want to add it back.
=head2 options_sanity_check( %opts )
Checks for sane command-line options. For example, I<-l> doesn't
make sense with I<-C>.
=cut
sub options_sanity_check {
my %opts = @_;
my $ok = 1;
# List mode doesn't make sense with any of these
$ok = 0 if _option_conflict( \%opts, 'l', [qw( f g group o output passthru )] );
# Passthru negates the need for a lot of switches
$ok = 0 if _option_conflict( \%opts, 'passthru', [qw( f g group l )] );
# File-searching is definitely irrelevant on these
for my $switch ( qw( f g l ) ) {
$ok = 0 if _option_conflict( \%opts, $switch, [qw( A B C o group )] );
}
# No sense to have negation with -o or --output
for my $switch ( qw( v ) ) {
$ok = 0 if _option_conflict( \%opts, $switch, [qw( o output passthru )] );
}
return $ok;
}
sub _option_conflict {
my $opts = shift;
my $used = shift;
my $exclusives = shift;
return if not defined $opts->{$used};
my $bad = 0;
for my $opt ( @{$exclusives} ) {
if ( defined $opts->{$opt} ) {
print 'The ', _opty($opt), ' option cannot be used with the ', _opty($used), " option.\n";
$bad = 1;
}
}
return $bad;
}
sub _opty {
my $opt = shift;
return length($opt)>1 ? "--$opt" : "-$opt";
}
Jump to Line
Something went wrong with that request. Please try again.