1 |
commit: 26edaf8f93326085928dbd3c0606b80062b1ce6a |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat May 25 22:35:45 2019 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat May 25 22:43:01 2019 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=26edaf8f |
7 |
|
8 |
repoman: report error for unknown arguments (bug 686074) |
9 |
|
10 |
Bug: https://bugs.gentoo.org/686074 |
11 |
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org> |
12 |
|
13 |
repoman/lib/repoman/argparser.py | 33 +++++++++++++++++++++------------ |
14 |
1 file changed, 21 insertions(+), 12 deletions(-) |
15 |
|
16 |
diff --git a/repoman/lib/repoman/argparser.py b/repoman/lib/repoman/argparser.py |
17 |
index b87df95cd..fa0e6ff90 100644 |
18 |
--- a/repoman/lib/repoman/argparser.py |
19 |
+++ b/repoman/lib/repoman/argparser.py |
20 |
@@ -1,5 +1,5 @@ |
21 |
# repoman: Argument parser |
22 |
-# Copyright 2007-2017 Gentoo Foundation |
23 |
+# Copyright 2007-2019 Gentoo Authors |
24 |
# Distributed under the terms of the GNU General Public License v2 |
25 |
|
26 |
"""This module contains functions used in Repoman to parse CLI arguments.""" |
27 |
@@ -196,23 +196,32 @@ def parse_args(argv, repoman_default_opts): |
28 |
'--mode', dest='mode', choices=mode_keys, |
29 |
help='specify which mode repoman will run in (default=full)') |
30 |
|
31 |
- opts, args = parser.parse_known_args(argv[1:]) |
32 |
+ # Modes help is included earlier, in the parser description. |
33 |
+ parser.add_argument( |
34 |
+ 'mode_positional', nargs='?', metavar='mode', choices=mode_keys, |
35 |
+ help=argparse.SUPPRESS) |
36 |
+ |
37 |
+ opts = parser.parse_args(argv[1:]) |
38 |
|
39 |
if not opts.ignore_default_opts: |
40 |
default_opts = util.shlex_split(repoman_default_opts) |
41 |
if default_opts: |
42 |
- opts, args = parser.parse_known_args(default_opts + sys.argv[1:]) |
43 |
+ opts = parser.parse_args(default_opts + sys.argv[1:]) |
44 |
+ |
45 |
+ args = [] |
46 |
+ if opts.mode is not None: |
47 |
+ args.append(opts.mode) |
48 |
+ if opts.mode_positional is not None: |
49 |
+ args.append(opts.mode_positional) |
50 |
+ |
51 |
+ if len(set(args)) > 1: |
52 |
+ parser.error("multiple modes specified: %s" % " ".join(args)) |
53 |
+ |
54 |
+ opts.mode = args[0] if args else None |
55 |
|
56 |
if opts.mode == 'help': |
57 |
- parser.print_help(short=False) |
58 |
- |
59 |
- for arg in args: |
60 |
- if arg in modes: |
61 |
- if not opts.mode: |
62 |
- opts.mode = arg |
63 |
- break |
64 |
- else: |
65 |
- parser.error("invalid mode: %s" % arg) |
66 |
+ parser.print_help() |
67 |
+ parser.exit() |
68 |
|
69 |
if not opts.mode: |
70 |
opts.mode = 'full' |