Skip to content

Commit 9301226

Browse files
committed
app: config: Add support for appending to the config string
In some cases, and specifically in the manifest.group-filter and manifest.project-filter options, it is sometimes useful to be able to append to a value instead of replacing it completely. For example, assuming one wants to add to an existing group filter, without this patch the user needs to do: > west config manifest.group-filter > west config manifest.group-filter +unstable,-optional,+extras With this patch instead: > west config -a manifest.group-filter ,+extras Signed-off-by: Carles Cufi <[email protected]>
1 parent d6b34df commit 9301226

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/west/app/config.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
To set a value for <name>, type:
4949
west config <name> <value>
5050
51+
To append to a value for <name>, type:
52+
west config -a <name> <value>
53+
5154
To list all options and their values:
5255
west config -l
5356
@@ -111,7 +114,9 @@ def do_add_parser(self, parser_adder):
111114
help='delete an option in one config file')
112115
parser.add_argument('-D', '--delete-all', action='store_true',
113116
help="delete an option everywhere it's set")
114-
117+
parser.add_argument('-a', '--append', action='store_true',
118+
help='append to an existing value')
119+
115120
group = parser.add_argument_group(
116121
'configuration file to use (give at most one)')
117122
group.add_argument('--system', dest='configfile', nargs=0, action=Once,
@@ -135,11 +140,18 @@ def do_run(self, args, user_args):
135140
self.parser.error('-l cannot be combined with name argument')
136141
elif delete:
137142
self.parser.error('-l cannot be combined with -d or -D')
143+
elif args.append:
144+
self.parser.error('-l cannot be combined with -a')
138145
elif not args.name:
139146
self.parser.error('missing argument name '
140147
'(to list all options and values, use -l)')
141-
elif args.delete and args.delete_all:
142-
self.parser.error('-d cannot be combined with -D')
148+
elif args.delete:
149+
if args.delete_all:
150+
self.parser.error('-d cannot be combined with -D')
151+
elif args.append:
152+
self.parser.error('-d cannot be combined with -a')
153+
elif args.value is None and args.append:
154+
self.parser.error('-a requires a value')
143155

144156
if args.list:
145157
self.list(args)
@@ -194,8 +206,14 @@ def read(self, args):
194206
def write(self, args):
195207
self.check_config(args.name)
196208
what = args.configfile or LOCAL
209+
if args.append:
210+
value = self.config.get(args.name,
211+
configfile=args.configfile or ALL) or ''
212+
value += args.value
213+
else:
214+
value = args.value
197215
try:
198-
self.config.set(args.name, args.value, configfile=what)
216+
self.config.set(args.name, value, configfile=what)
199217
except PermissionError as pe:
200218
self._perm_error(pe, what, args.name)
201219

0 commit comments

Comments
 (0)