public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: Zac Medico <zmedico@gentoo.org>
To: gentoo-portage-dev@lists.gentoo.org
Cc: Zac Medico <zmedico@gentoo.org>
Subject: [gentoo-portage-dev] [PATCH] repoman: report error for unknown arguments (bug 686074)
Date: Sat, 25 May 2019 15:47:44 -0700	[thread overview]
Message-ID: <20190525224744.24601-1-zmedico@gentoo.org> (raw)

Bug: https://bugs.gentoo.org/686074
Signed-off-by: Zac Medico <zmedico@gentoo.org>
---
 repoman/lib/repoman/argparser.py | 33 ++++++++++++++++++++------------
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/repoman/lib/repoman/argparser.py b/repoman/lib/repoman/argparser.py
index b87df95cd..fa0e6ff90 100644
--- a/repoman/lib/repoman/argparser.py
+++ b/repoman/lib/repoman/argparser.py
@@ -1,5 +1,5 @@
 # repoman: Argument parser
-# Copyright 2007-2017 Gentoo Foundation
+# Copyright 2007-2019 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 """This module contains functions used in Repoman to parse CLI arguments."""
@@ -196,23 +196,32 @@ def parse_args(argv, repoman_default_opts):
 		'--mode', dest='mode', choices=mode_keys,
 		help='specify which mode repoman will run in (default=full)')
 
-	opts, args = parser.parse_known_args(argv[1:])
+	# Modes help is included earlier, in the parser description.
+	parser.add_argument(
+		'mode_positional', nargs='?', metavar='mode', choices=mode_keys,
+		help=argparse.SUPPRESS)
+
+	opts = parser.parse_args(argv[1:])
 
 	if not opts.ignore_default_opts:
 		default_opts = util.shlex_split(repoman_default_opts)
 		if default_opts:
-			opts, args = parser.parse_known_args(default_opts + sys.argv[1:])
+			opts = parser.parse_args(default_opts + sys.argv[1:])
+
+	args = []
+	if opts.mode is not None:
+		args.append(opts.mode)
+	if opts.mode_positional is not None:
+		args.append(opts.mode_positional)
+
+	if len(set(args)) > 1:
+		parser.error("multiple modes specified: %s" % " ".join(args))
+
+	opts.mode = args[0] if args else None
 
 	if opts.mode == 'help':
-		parser.print_help(short=False)
-
-	for arg in args:
-		if arg in modes:
-			if not opts.mode:
-				opts.mode = arg
-				break
-		else:
-			parser.error("invalid mode: %s" % arg)
+		parser.print_help()
+		parser.exit()
 
 	if not opts.mode:
 		opts.mode = 'full'
-- 
2.21.0



                 reply	other threads:[~2019-05-25 22:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190525224744.24601-1-zmedico@gentoo.org \
    --to=zmedico@gentoo.org \
    --cc=gentoo-portage-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox