forked from beyondgrep/ack1
-
Notifications
You must be signed in to change notification settings - Fork 1
/
TODO
60 lines (43 loc) · 1.44 KB
/
TODO
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# 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";
}