From 0e51dddf3c9cbe1c3fc97176ee45fed62f6719ee Mon Sep 17 00:00:00 2001 From: Jim Salter Date: Fri, 20 Mar 2015 17:56:39 -0400 Subject: [PATCH] extended improved argument parsing to syncoid also --- syncoid | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/syncoid b/syncoid index 7383607..c589762 100755 --- a/syncoid +++ b/syncoid @@ -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;