Browse files

Add -s option

This closes #68
  • Loading branch information...
1 parent 0c29623 commit e4e9f9ca4ddb801afbc2987df75d1fa24806e86d @hoelzro hoelzro committed Oct 16, 2012
Showing with 49 additions and 36 deletions.
  1. +3 −0 Ack.pm
  2. +6 −5 Basic.pm
  3. +1 −0 ConfigLoader.pm
  4. +8 −1 ack
  5. +31 −30 t/config-loader.t
View
3 Ack.pm
@@ -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,
View
11 Basic.pm
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -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() . ": $!" );
}
View
1 ConfigLoader.pm
@@ -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},
View
9 ack
@@ -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;
}
@@ -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" );
}
}
@@ -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
View
61 t/config-loader.t
@@ -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(

0 comments on commit e4e9f9c

Please sign in to comment.