Skip to content

Commit c8d62f6

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: (assuming the group filter is currently +unstable,-optional, and the user wants to add +extras). > 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 c8d62f6

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

src/west/app/config.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@
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+
A value must exist in the selected configuration file in order to be able
54+
to append to it.
55+
5156
To list all options and their values:
5257
west config -l
5358
@@ -64,7 +69,7 @@
6469

6570
CONFIG_EPILOG = '''\
6671
If the configuration file to use is not set, reads use all three in
67-
precedence order, and writes use the local file.'''
72+
precedence order, and writes (including appends) use the local file.'''
6873

6974
ALL = ConfigFile.ALL
7075
SYSTEM = ConfigFile.SYSTEM
@@ -111,6 +116,8 @@ def do_add_parser(self, parser_adder):
111116
help='delete an option in one config file')
112117
parser.add_argument('-D', '--delete-all', action='store_true',
113118
help="delete an option everywhere it's set")
119+
parser.add_argument('-a', '--append', action='store_true',
120+
help='append to an existing value')
114121

115122
group = parser.add_argument_group(
116123
'configuration file to use (give at most one)')
@@ -135,18 +142,27 @@ def do_run(self, args, user_args):
135142
self.parser.error('-l cannot be combined with name argument')
136143
elif delete:
137144
self.parser.error('-l cannot be combined with -d or -D')
145+
elif args.append:
146+
self.parser.error('-l cannot be combined with -a')
138147
elif not args.name:
139148
self.parser.error('missing argument name '
140149
'(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')
150+
elif args.delete:
151+
if args.delete_all:
152+
self.parser.error('-d cannot be combined with -D')
153+
elif args.append:
154+
self.parser.error('-d cannot be combined with -a')
155+
elif args.value is None and args.append:
156+
self.parser.error('-a requires a value')
143157

144158
if args.list:
145159
self.list(args)
146160
elif delete:
147161
self.delete(args)
148162
elif args.value is None:
149163
self.read(args)
164+
elif args.append:
165+
self.append(args)
150166
else:
151167
self.write(args)
152168

@@ -191,6 +207,16 @@ def read(self, args):
191207
self.dbg(f'{args.name} is unset')
192208
raise CommandError(returncode=1)
193209

210+
def append(self, args):
211+
self.check_config(args.name)
212+
what = args.configfile or LOCAL
213+
value = self.config.get(args.name, configfile=what)
214+
if value is None:
215+
self.die(f'option {args.name} not found in {what.name.lower()} '
216+
'configuration file')
217+
args.value = value + args.value
218+
self.write(args)
219+
194220
def write(self, args):
195221
self.check_config(args.name)
196222
what = args.configfile or LOCAL

0 commit comments

Comments
 (0)