Skip to content

Commit

Permalink
rev: retire -v option (#581)
Browse files Browse the repository at this point in the history
* GNU rev has flags -V and --version for printing version, but on {Free,Open,Net}BSD rev has neither
* Simplify getopts() usage by removing -v and defining VERSION_MESSAGE() which allows --version to work
* Sync pod; --version deliberately omitted from usage string
* Explicitly close() files so an error can be printed if this fails
  • Loading branch information
mknos committed Apr 26, 2024
1 parent 8019f02 commit 4c0ef0f
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions bin/rev
Expand Up @@ -24,15 +24,9 @@ my $Program = basename($0);
# unbuffer output to make it look speedier
$|++;

my ($VERSION) = '1.4';

my %opt;
getopts('v', \%opt) or usage();
if ($opt{'v'}) {
print "$Program $VERSION\n";
exit EX_SUCCESS;
}
our $VERSION = '1.5';

getopts('') or usage();
my $rc = EX_SUCCESS;
foreach my $file (@ARGV) {
if (-d $file) {
Expand All @@ -51,6 +45,11 @@ foreach my $file (@ARGV) {
warn "$Program: '$file': $!\n";
$rc = EX_FAILURE;
}
unless (close $fh) {
warn "$Program: cannot close '$file': $!\n";
$rc = EX_FAILURE;
next;
}
}
rev(*STDIN) unless @ARGV;
exit $rc;
Expand All @@ -65,18 +64,15 @@ sub rev {
}

sub usage {
print <<EOF;
Usage: $Program [OPTION] [FILE]...
Reverse lines of the named file(s) or the text input on STDIN
Options:
-v Print version number, then exit.
EOF
print "usage: $Program [file ...]\n";
exit EX_FAILURE;
}

sub VERSION_MESSAGE {
print "$Program version $VERSION\n";
exit EX_SUCCESS;
}

__END__
=pod
Expand All @@ -87,7 +83,7 @@ rev - reverse lines of a file
=head1 SYNOPSIS
rev [-v] [file]...
rev [file ...]
=head1 DESCRIPTION
Expand All @@ -101,7 +97,7 @@ I<rev> accepts the following options:
=over 4
=item -v
=item --version
Print version number then exit
Expand Down

0 comments on commit 4c0ef0f

Please sign in to comment.