Skip to content

Commit

Permalink
Add -s option
Browse files Browse the repository at this point in the history
This closes #68
  • Loading branch information
hoelzro committed Oct 16, 2012
1 parent 0c29623 commit e4e9f9c
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 36 deletions.
3 changes: 3 additions & 0 deletions Ack.pm
Expand Up @@ -425,6 +425,9 @@ Search output:
--print0 Print null byte as separator between filenames,
only works with -f, -g, -l, -L or -c.
-s Suppress error messages about nonexistent or
unreadable files.
File presentation:
--pager=COMMAND Pipes all ack output through COMMAND. For example,
Expand Down
11 changes: 6 additions & 5 deletions Basic.pm
Expand Up @@ -34,7 +34,7 @@ sub new {
$self->{fh} = *STDIN;
}
else {
if ( !open( $self->{fh}, '<', $self->{filename} ) ) {
if ( !open( $self->{fh}, '<', $self->{filename} ) && $App::Ack::report_bad_filenames ) {
App::Ack::warn( "$self->{filename}: $!" );
return;
}
Expand Down Expand Up @@ -86,7 +86,7 @@ sub needs_line_scan {

my $buffer;
my $rc = sysread( $self->{fh}, $buffer, $size );
if ( not defined $rc ) {
if ( !defined($rc) && $App::Ack::report_bad_filenames ) {
App::Ack::warn( "$self->{filename}: $!" );
return 1;
}
Expand All @@ -107,8 +107,9 @@ is true.
sub reset {
my $self = shift;

seek( $self->{fh}, 0, 0 )
or App::Ack::warn( "$self->{filename}: $!" );
if( !seek( $self->{fh}, 0, 0 ) && $App::Ack::report_bad_filenames ) {
App::Ack::warn( "$self->{filename}: $!" );
}

return;
}
Expand Down Expand Up @@ -143,7 +144,7 @@ API: Close the resource.
sub close {
my $self = shift;

if ( not close $self->{fh} ) {
if ( !close($self->{fh}) && $App::Ack::report_bad_filenames ) {
App::Ack::warn( $self->name() . ": $!" );
}

Expand Down
1 change: 1 addition & 0 deletions ConfigLoader.pm
Expand Up @@ -230,6 +230,7 @@ EOT
'print0' => \$opt->{print0},
'Q|literal' => \$opt->{Q},
'r|R|recurse' => sub { $opt->{n} = 0 },
's' => \$opt->{dont_report_bad_filenames},
'show-types' => \$opt->{show_types},
'smart-case!' => \$opt->{smart_case},
'sort-files' => \$opt->{sort_files},
Expand Down
9 changes: 8 additions & 1 deletion ack
Expand Up @@ -176,6 +176,8 @@ sub main {

my $opt = App::Ack::ConfigLoader::process_args( @arg_sources );

$App::Ack::report_bad_filenames = !$opt->{dont_report_bad_filenames};

if ( $opt->{flush} ) {
$| = 1;
}
Expand Down Expand Up @@ -227,7 +229,7 @@ sub main {
else {
@start = ('.') unless @start;
foreach my $target (@start) {
if ( not -e $target ) {
if ( !-e $target && $App::Ack::report_bad_filenames) {
App::Ack::warn( "$target: No such file or directory" );
}
}
Expand Down Expand Up @@ -656,6 +658,11 @@ and B<-G> options.
Recurse into sub-directories. This is the default and just here for
compatibility with grep. You can also use it for turning B<--no-recurse> off.
=item B<-s>
Supress error messages about nonexistent or unreadable files. This is taken
from fgrep.
=item B<--smart-case>, B<--no-smart-case>
Ignore case in the search strings if PATTERN contains no uppercase
Expand Down
61 changes: 31 additions & 30 deletions t/config-loader.t
Expand Up @@ -63,36 +63,37 @@ sub test_loader {
}

my %defaults = (
after_context => undef,
before_context => undef,
'break' => undef,
color => undef,
column => undef,
count => undef,
f => undef,
files_from => undef,
filters => [ App::Ack::Filter::Default->new ],
flush => undef,
follow => undef,
g => undef,
h => undef,
H => undef,
heading => undef,
i => undef,
l => undef,
m => undef,
n => undef,
output => undef,
pager => undef,
passthru => undef,
print0 => undef,
Q => undef,
regex => undef,
show_types => undef,
smart_case => undef,
sort_files => undef,
v => undef,
w => undef,
after_context => undef,
before_context => undef,
'break' => undef,
color => undef,
column => undef,
count => undef,
dont_report_bad_filenames => undef,
f => undef,
files_from => undef,
filters => [ App::Ack::Filter::Default->new ],
flush => undef,
follow => undef,
g => undef,
h => undef,
H => undef,
heading => undef,
i => undef,
l => undef,
m => undef,
n => undef,
output => undef,
pager => undef,
passthru => undef,
print0 => undef,
Q => undef,
regex => undef,
show_types => undef,
smart_case => undef,
sort_files => undef,
v => undef,
w => undef,
);

test_loader(
Expand Down

0 comments on commit e4e9f9c

Please sign in to comment.