|
48 | 48 | To set a value for <name>, type: |
49 | 49 | west config <name> <value> |
50 | 50 |
|
| 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. The existing value can be empty. |
| 55 | +Examples: |
| 56 | + west config -a build.cmake-args -- " -DEXTRA_CFLAGS='-Wextra -g0' -DFOO=BAR" |
| 57 | + west config -a manifest.group-filter ,+optional |
| 58 | +
|
51 | 59 | To list all options and their values: |
52 | 60 | west config -l |
53 | 61 |
|
|
64 | 72 |
|
65 | 73 | CONFIG_EPILOG = '''\ |
66 | 74 | If the configuration file to use is not set, reads use all three in |
67 | | -precedence order, and writes use the local file.''' |
| 75 | +precedence order, and writes (including appends) use the local file.''' |
68 | 76 |
|
69 | 77 | ALL = ConfigFile.ALL |
70 | 78 | SYSTEM = ConfigFile.SYSTEM |
@@ -92,13 +100,14 @@ def do_add_parser(self, parser_adder): |
92 | 100 | "action to perform (give at most one)" |
93 | 101 | ).add_mutually_exclusive_group() |
94 | 102 |
|
95 | | - |
96 | 103 | group.add_argument('-l', '--list', action='store_true', |
97 | 104 | help='list all options and their values') |
98 | 105 | group.add_argument('-d', '--delete', action='store_true', |
99 | 106 | help='delete an option in one config file') |
100 | 107 | group.add_argument('-D', '--delete-all', action='store_true', |
101 | 108 | help="delete an option everywhere it's set") |
| 109 | + group.add_argument('-a', '--append', action='store_true', |
| 110 | + help='append to an existing value') |
102 | 111 |
|
103 | 112 | group = parser.add_argument_group( |
104 | 113 | "configuration file to use (give at most one)" |
@@ -129,13 +138,18 @@ def do_run(self, args, user_args): |
129 | 138 | elif not args.name: |
130 | 139 | self.parser.error('missing argument name ' |
131 | 140 | '(to list all options and values, use -l)') |
| 141 | + elif args.append: |
| 142 | + if args.value is None: |
| 143 | + self.parser.error('-a requires both name and value') |
132 | 144 |
|
133 | 145 | if args.list: |
134 | 146 | self.list(args) |
135 | 147 | elif delete: |
136 | 148 | self.delete(args) |
137 | 149 | elif args.value is None: |
138 | 150 | self.read(args) |
| 151 | + elif args.append: |
| 152 | + self.append(args) |
139 | 153 | else: |
140 | 154 | self.write(args) |
141 | 155 |
|
@@ -180,6 +194,16 @@ def read(self, args): |
180 | 194 | self.dbg(f'{args.name} is unset') |
181 | 195 | raise CommandError(returncode=1) |
182 | 196 |
|
| 197 | + def append(self, args): |
| 198 | + self.check_config(args.name) |
| 199 | + where = args.configfile or LOCAL |
| 200 | + value = self.config.get(args.name, configfile=where) |
| 201 | + if value is None: |
| 202 | + self.die(f'option {args.name} not found in the {where.name.lower()} ' |
| 203 | + 'configuration file') |
| 204 | + args.value = value + args.value |
| 205 | + self.write(args) |
| 206 | + |
183 | 207 | def write(self, args): |
184 | 208 | self.check_config(args.name) |
185 | 209 | what = args.configfile or LOCAL |
|
0 commit comments