diff --git a/src/west/app/config.py b/src/west/app/config.py index cfb5236b..7acefb8f 100644 --- a/src/west/app/config.py +++ b/src/west/app/config.py @@ -48,6 +48,9 @@ To set a value for , type: west config +To append to a value for , type: + west config -a + To list all options and their values: west config -l @@ -111,6 +114,8 @@ def do_add_parser(self, parser_adder): 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") + parser.add_argument('-a', '--append', action='store_true', + help='append to an existing value') group = parser.add_argument_group( 'configuration file to use (give at most one)') @@ -135,11 +140,18 @@ def do_run(self, args, user_args): self.parser.error('-l cannot be combined with name argument') elif delete: self.parser.error('-l cannot be combined with -d or -D') + elif args.append: + self.parser.error('-l cannot be combined with -a') 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') + elif args.delete: + if args.delete_all: + self.parser.error('-d cannot be combined with -D') + elif args.append: + self.parser.error('-d cannot be combined with -a') + elif args.value is None and args.append: + self.parser.error('-a requires a value') if args.list: self.list(args) @@ -147,6 +159,8 @@ def do_run(self, args, user_args): self.delete(args) elif args.value is None: self.read(args) + elif args.append: + self.append(args) else: self.write(args) @@ -182,14 +196,23 @@ def check_config(self, option): self.die(f'invalid configuration option "{option}"; ' 'expected "section.key" format') + def _read(self, name, configfile): + value = self.config.get(name, configfile=configfile) + if value is None: + self.dbg(f'{name} is unset') + raise CommandError(returncode=1) + return value + def read(self, args): self.check_config(args.name) - value = self.config.get(args.name, configfile=args.configfile or ALL) - if value is not None: - self.inf(value) - else: - self.dbg(f'{args.name} is unset') - raise CommandError(returncode=1) + value = self._read(args.name, args.configfile or ALL) + self.inf(value) + + def append(self, args): + self.check_config(args.name) + value = self._read(args.name, args.configfile or ALL) or '' + args.value = value + args.value + self.write(args) def write(self, args): self.check_config(args.name)