extended improved argument parsing to syncoid also

This commit is contained in:
Jim Salter 2015-03-20 17:56:39 -04:00
parent 3cd393fc23
commit 0e51dddf3c
1 changed files with 15 additions and 7 deletions

22
syncoid
View File

@ -168,21 +168,28 @@ sub getargs {
my @args = @_;
my %args;
my $novalueargs = ",debug,nocommandchecks,version,monitor-version,";
my %novaluearg;
my %validarg;
push my @validargs, ('debug','nocommandchecks','version','monitor-version','compress','source-bwlimit','target-bwlimit');
foreach my $item (@validargs) { $validarg{$item} = 1; }
push my @novalueargs, ('debug','nocommandchecks','version','monitor-version');
foreach my $item (@novalueargs) { $novaluearg{$item} = 1; }
while (my $arg = shift(@args)) {
while (my $rawarg = shift(@args)) {
my $arg = $rawarg;
my $argvalue;
if ($arg =~ /=/) {
if ($rawarg =~ /=/) {
# user specified the value for a CLI argument with =
# instead of with blank space. separate appropriately.
$argvalue = $arg;
$arg =~ s/=.*$//;
$argvalue =~ s/^.*=//;
}
if ($arg =~ /^--/) {
if ($rawarg =~ /^--/) {
# doubledash arg
$arg =~ s/^--//;
if ($novalueargs =~ /,$arg,/) {
if (! $validarg{$arg}) { die "ERROR: don't understand argument $rawarg.\n"; }
if ($novaluearg{$arg}) {
$args{$arg} = 1;
} else {
# if this CLI arg takes a user-specified value and
@ -196,7 +203,8 @@ sub getargs {
} elsif ($arg =~ /^-/) {
# singledash arg
$arg =~ s/^-//;
if ($novalueargs =~ /,$arg,/) {
if (! $validarg{$arg}) { die "ERROR: don't understand argument $rawarg.\n"; }
if ($novaluearg{$arg}) {
$args{$arg} = 1;
} else {
# if this CLI arg takes a user-specified value and
@ -213,7 +221,7 @@ sub getargs {
if (! defined $args{'target'}) {
$args{'target'} = $arg;
} else {
die "ERROR: don't know what to do with a third bare argument.\n";
die "ERROR: don't know what to do with third bare argument $rawarg.\n";
}
} else {
$args{'source'} = $arg;