Skip to content

Commit

Permalink
app: config: Use mutually-exclusive groups for config actions
Browse files Browse the repository at this point in the history
Simplify the error handling of the different action flags (-l, -d and
-D) by using a parser mutually exclusive group.

Signed-off-by: Carles Cufi <[email protected]>
  • Loading branch information
carlescufi committed Nov 26, 2024
1 parent 2b18ae4 commit 385f5e0
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/west/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,17 @@ def do_add_parser(self, parser_adder):
description=self.description,
epilog=CONFIG_EPILOG)

parser.add_argument('-l', '--list', action='store_true',
help='list all options and their values')
parser.add_argument('-d', '--delete', action='store_true',
help='delete an option in one config file')
parser.add_argument('-D', '--delete-all', action='store_true',
help="delete an option everywhere it's set")
group = parser.add_argument_group(
"action to perform (give at most one)"
).add_mutually_exclusive_group()


group.add_argument('-l', '--list', action='store_true',
help='list all options and their values')
group.add_argument('-d', '--delete', action='store_true',
help='delete an option in one config file')
group.add_argument('-D', '--delete-all', action='store_true',
help="delete an option everywhere it's set")

group = parser.add_argument_group(
"configuration file to use (give at most one)"
Expand Down Expand Up @@ -121,13 +126,9 @@ def do_run(self, args, user_args):
if args.list:
if args.name:
self.parser.error('-l cannot be combined with name argument')
elif delete:
self.parser.error('-l cannot be combined with -d or -D')
elif not args.name:
self.parser.error('missing argument name '
'(to list all options and values, use -l)')
elif args.delete and args.delete_all:
self.parser.error('-d cannot be combined with -D')

if args.list:
self.list(args)
Expand Down

0 comments on commit 385f5e0

Please sign in to comment.