Skip to content

Commit 01c8f69

Browse files
committed
starting on fixing booleans for -g
1 parent ac48579 commit 01c8f69

5 files changed

Lines changed: 34 additions & 16 deletions

File tree

ack

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,12 @@ sub _compile_file_filter {
440440

441441
return sub {
442442
if ( $opt_g ) {
443-
if ( $File::Next::name =~ /$re_match/o ) {
443+
my $match = ($File::Next::name =~ /$re_match/o);
444+
if ( $match && $re_not ) {
445+
$match = ($File::Next::name !~ /$re_not/o);
446+
}
447+
448+
if ( $match ) {
444449
return 0 if $opt_v;
445450
}
446451
else {

dev/crank-mutex

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ sub invalid_combinations {
1515
my @output = qw( -o --output );
1616
my @fg = qw( -f -g );
1717
my @case = qw( -i -I --smart-case );
18-
my @booleans = qw( --and --or --not );
1918

2019
return (
21-
[qw(--or)] => [qw( --and --not )],
20+
[qw(--and)] => [qw( --or )],
2221
[qw(-l)] => [@context, @file_lists, @pretty, @filename, @output, qw(--passthru --column --show-types)],
2322
[qw(-L)] => [@context, @file_lists, @pretty, @filename, @output, qw(--passthru --column --show-types -c -v)],
2423
[@output] => [@context, @file_lists, @output, qw(-c --column --show-types)],
@@ -31,7 +30,6 @@ sub invalid_combinations {
3130
[qw(--column)] => [@file_lists],
3231
[@context] => [@file_lists],
3332
[qw(-f)] => [qw(-v), @case],
34-
[qw(-g)] => [@booleans],
3533
[@fg] => [@fg, @pretty, qw(-x -c -u --files-from)],
3634
[qw(-p)] => [@context, @file_lists, qw(--passthru -c)],
3735
[qw(-v)] => [qw(--column -o --output --passthru)],

lib/App/Ack.pm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ sub build_all_regexes {
841841

842842
my @parts;
843843

844-
# AND: alpha and beta
844+
# AND: alpha AND beta
845845
if ( @parts = @{$opt->{and}} ) {
846846
my @match_parts;
847847
my @hilite_parts;
@@ -875,8 +875,9 @@ sub build_all_regexes {
875875
$re_hilite = $re_match;
876876
$re_scan = join( '|', @scan_parts );
877877
}
878+
878879
# NOT: alpha NOT beta
879-
elsif ( @parts = @{$opt->{not}} ) {
880+
if ( @parts = @{$opt->{not}} ) {
880881
($re_match, $re_scan) = build_regex( $opt_regex, $opt );
881882
$re_hilite = $re_match;
882883

lib/App/Ack/ConfigLoader.pm

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,6 @@ sub mutex_options {
933933
'with-filename' => 1,
934934
},
935935
and => {
936-
g => 1,
937936
or => 1,
938937
},
939938
break => {
@@ -1011,7 +1010,6 @@ sub mutex_options {
10111010
C => 1,
10121011
H => 1,
10131012
L => 1,
1014-
and => 1,
10151013
break => 1,
10161014
c => 1,
10171015
column => 1,
@@ -1024,9 +1022,7 @@ sub mutex_options {
10241022
l => 1,
10251023
m => 1,
10261024
match => 1,
1027-
not => 1,
10281025
o => 1,
1029-
or => 1,
10301026
output => 1,
10311027
p => 1,
10321028
passthru => 1,
@@ -1093,10 +1089,6 @@ sub mutex_options {
10931089
L => 1,
10941090
l => 1,
10951091
},
1096-
not => {
1097-
g => 1,
1098-
or => 1,
1099-
},
11001092
o => {
11011093
A => 1,
11021094
B => 1,
@@ -1116,8 +1108,6 @@ sub mutex_options {
11161108
},
11171109
or => {
11181110
and => 1,
1119-
g => 1,
1120-
not => 1,
11211111
},
11221112
output => {
11231113
A => 1,

t/ack-g.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,27 @@ stdout: |
119119
t/text/numbered-text.txt
120120
t/text/ozymandias.txt
121121
t/text/raven.txt
122+
123+
---
124+
name: -g and --and
125+
args: -g foo --and test t/
126+
stdout:
127+
t/swamp/foo_test.py
128+
t/swamp/test_foo.py
129+
130+
---
131+
name: -g and --not
132+
args: -g foo --not test t/
133+
stdout:
134+
t/etc/shebang.foobar.xxx
135+
t/swamp/file.foo
136+
137+
---
138+
name: -g and --or
139+
args: -g foo --or test t/
140+
stdout:
141+
t/etc/shebang.foobar.xxx
142+
t/swamp/file.bar
143+
t/swamp/file.foo
144+
t/swamp/foo_test.py
145+
t/swamp/test_foo.py

0 commit comments

Comments
 (0)