From 55fd4d560864deee38a9e616b94f54c20791eb2d Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Wed, 18 Aug 2021 02:58:51 -0700 Subject: [PATCH] projtool.pl: use parse_options everywhere Replace remaining ancient code that directly inspected @ARGV with a call to parse_options instead. It's more robust, simpler to use and matches the rest of the code. Signed-off-by: Kyle J. McKay --- toolbox/projtool.pl | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/toolbox/projtool.pl b/toolbox/projtool.pl index af61714..6c97cc7 100755 --- a/toolbox/projtool.pl +++ b/toolbox/projtool.pl @@ -1423,7 +1423,7 @@ sub cmd_listheads { sub cmd_listtags { my $vcnt = 0; - shift(@ARGV), $vcnt=1 if @ARGV && ($ARGV[0] eq '--verbose' || $ARGV[0] eq '-v'); + parse_options("verbose" => \$vcnt, "v" => \$vcnt); @ARGV == 1 or die_usage; my $project = get_project_harder($ARGV[0]); if ($vcnt) { @@ -1436,7 +1436,7 @@ sub cmd_listtags { sub cmd_deltags { my $ic = 0; - shift(@ARGV), $ic=1 if @ARGV && $ARGV[0] =~ /^(?:--?ignore-case|-i)$/i; + parse_options("ignore-case" => \$ic, "i" => \$ic); @ARGV >= 2 or die_usage; my $project = get_project_harder(shift @ARGV); my %curtags; @@ -1501,7 +1501,7 @@ sub _get_random_val { sub cmd_chpass { my $force = 0; - shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force'; + parse_options("force" => \$force); my $random = undef; pop(@ARGV), $random=lc($ARGV[1]) if @ARGV==2 && $ARGV[1] =~ /^(?:random|unknown)$/i; @ARGV == 1 or die_usage; @@ -1661,7 +1661,7 @@ sub cmd_remirror { sub cmd_setowner { my $force = 0; - shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force'; + parse_options("force" => \$force); @ARGV == 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage; my $project = get_project_harder($ARGV[0]); if (@ARGV == 2 && !valid_email($ARGV[1])) { @@ -1693,7 +1693,7 @@ sub cmd_setowner { sub cmd_setdesc { my $force = 0; - shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force'; + parse_options("force" => \$force); @ARGV >= 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage; my $project = get_project_harder(shift @ARGV); if (@ARGV && !valid_desc(join(" ", @ARGV))) { @@ -1836,7 +1836,7 @@ sub cmd_sethead { sub cmd_sethooks { my $force = 0; - shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force'; + parse_options(force => \$force); @ARGV == 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage; my $project = get_project_harder($ARGV[0]); my $projconfig = read_config_file_hash($project->{path}."/config"); @@ -1921,7 +1921,7 @@ BEGIN { sub cmd_setbool { my $force = 0; - shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force'; + parse_options("force" => \$force); @ARGV == 3 || (@ARGV == 2 && !$force && !$setopt) or die_usage; my $project = get_project_harder($ARGV[0]); if (!exists($boolfields{$ARGV[1]})) { @@ -2061,7 +2061,7 @@ BEGIN { sub cmd_seturl { my $force = 0; - shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force'; + parse_options("force" => \$force); @ARGV == 3 || (@ARGV == 2 && !$force && !$setopt) or die_usage; my $project = get_project_harder($ARGV[0]); if (!exists($urlfields{$ARGV[1]})) { @@ -2107,7 +2107,7 @@ BEGIN { sub cmd_setmsgs { my $force = 0; - shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force'; + parse_options("force" => \$force); @ARGV >= 3 || (@ARGV == 2 && !$force && !$setopt) or die_usage; my $project = get_project_harder(shift @ARGV); my $field = shift @ARGV; @@ -2137,7 +2137,7 @@ sub cmd_setmsgs { sub cmd_setusers { my $force = 0; - shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force'; + parse_options("force" => \$force); @ARGV >= 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage; my $project = get_project_harder(shift @ARGV); my $projname = $project->{name}; -- 2.11.4.GIT