Skip to content

Commit

Permalink
par: reject bad options
Browse files Browse the repository at this point in the history
* Change par to raise a fatal error if invalid options are passed, e.g. "perl par -X"
* Change the order or ARGV check to after getopts() call, so that an option is not counted incorrectly as a file argument, e.g. "perl par -S"
  • Loading branch information
mknos authored Oct 3, 2024
1 parent 97648b6 commit 9f32222
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions bin/par
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ my $VERSION = '0.08';

use File::Find;
use File::Basename;
use Getopt::Std qw(getopts);
use Cwd;

eval 'use Stat::lsMode';
Expand All @@ -35,21 +36,13 @@ binmode STDOUT;
# Are we 'par' or 'shar'?
($0) = $0 =~ /(\w+)$/;

# Check for arguments.
@ARGV or die "usage: $0 [-s submitter] [-STBqvz] file [files...]\n";
sub usage {
die "usage: $0 [-s submitter] [-STBqvz] file...\n";
}

# Get options.
my %opts;
while (@ARGV && $ARGV[0] =~ s/^-//) {
local $_ = shift;
while (/([sSTBVqvz])/g) {
if ($1 eq 's') {
$opts{'s'} = /\G(.*)/g && $1 ? $1 : shift;
} else {
$opts{$1}++;
}
}
}
getopts('s:STBqvz', \%opts) or usage();
@ARGV or usage();

# Print version.
if ($opts{'v'}) {
Expand Down

0 comments on commit 9f32222

Please sign in to comment.