Skip to content

Commit

Permalink
uniq: print usage for invalid options
Browse files Browse the repository at this point in the history
* Retire undocumented flags -? and -h (usage is still printed)
* Prefix usage string with "usage: "

%perl uniq -x
uniq: invalid option -- -x
usage: uniq [-c | -d | -u] [-f fields] [-s chars] [input files]
  • Loading branch information
mknos authored Jan 28, 2024
1 parent efd40be commit cc20662
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions bin/uniq
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ END {
$? = 1 if $? == 255; # from die
}

sub help {
print "$0 [-c | -d | -u] [-f fields] [-s chars] [input files]\n";
exit 0;
sub usage {
print "usage: $0 [-c | -d | -u] [-f fields] [-s chars] [input files]\n";
exit 1;
}

sub version { print "$0 (Perl Power Tools) $VERSION\n"; exit 0; }
Expand All @@ -46,7 +46,6 @@ sub get_numeric_arg {
while (@ARGV && $ARGV[0] =~ /^[-+]/) {
local $_ = shift;
last if ($_ eq '--');
/^-[h?]$/ && help(); # terminates
/^-v$/ && version(); # terminates
/^-c$/ && ($optc++, next);
/^-d$/ && ($optd++, next);
Expand All @@ -56,7 +55,8 @@ while (@ARGV && $ARGV[0] =~ /^[-+]/) {
s/^-f// && (($optf = get_numeric_arg('f', 'fields to skip')), next);
s/^-s// && (($opts = get_numeric_arg('s', 'bytes to skip')), next);

die "$0: invalid option -- $_\n";
warn "$0: invalid option -- $_\n";
usage();
}

my ($comp, $save_comp, $line, $save_line, $count, $eof);
Expand Down

0 comments on commit cc20662

Please sign in to comment.