-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
app: config: Add support for appending to the config string #768
base: main
Are you sure you want to change the base?
Conversation
9301226
to
717a09c
Compare
717a09c
to
e46a0d4
Compare
I do have a concern about the appending if the value doesn't exist yet. Something like: $ west config -a manifest.group-filter ,+extras Could result in an error because of the leading comma. |
I also thought about that, but did not want to overcomplicate the code. But yes, let me do that as well. |
e46a0d4
to
7a7c2e3
Compare
37e03bc
to
69ac4f1
Compare
c8d62f6
to
3cf5a27
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, can you add tests?
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 <carles.cufi@nordicsemi.no>
3cf5a27
to
4d8d948
Compare
yep, on it! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, can you add tests?
yep, on it!
I think these won't involve shlex.split()
because Zephyr will not be involved but please use some whitespace anyway in test data for more "stress".
To append to a value for <name>, type: | ||
west config -a <name> <value> | ||
A value must exist in the selected configuration file in order to be able | ||
to append to it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add a short example? One with whitespace, quoting and shlex.split()
to warn the user about the usual whitespace and quoting perils. Something like west config -a build.cmake-args -- "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_VERBOSE_MAKEFILE=ON"
(UNTESTED)
See https://docs.zephyrproject.org/latest/develop/west/build-flash-debug.html#permanent-cmake-arguments and 0186eade513a
elif args.delete and args.delete_all: | ||
self.parser.error('-d cannot be combined with -D') | ||
elif args.value is None and args.append: | ||
self.parser.error('-a requires a value') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.parser.error('-a requires a value') | |
self.parser.error('-a requires both name and value') |
@@ -179,6 +190,16 @@ def read(self, args): | |||
self.dbg(f'{args.name} is unset') | |||
raise CommandError(returncode=1) | |||
|
|||
def append(self, args): | |||
self.check_config(args.name) | |||
what = args.configfile or LOCAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what = args.configfile or LOCAL | |
where = args.configfile or LOCAL |
To append to a value for <name>, type: | ||
west config -a <name> <value> | ||
A value must exist in the selected configuration file in order to be able | ||
to append to it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to append to it. | |
to append to it. The existing value can be empty. |
@@ -64,7 +69,7 @@ | |||
|
|||
CONFIG_EPILOG = '''\ | |||
If the configuration file to use is not set, reads use all three in | |||
precedence order, and writes use the local file.''' | |||
precedence order, and writes (including appends) use the local file.''' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid you just discovered a documentation bug (or worse). The west config
command works just fine outside of any workspace - when there is no "local file"! What happens then?
group.add_argument('-D', '--delete-all', action='store_true', | ||
help="delete an option everywhere it's set") | ||
group.add_argument('-a', '--append', action='store_true', | ||
help='append to an existing value') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice simplification thanks to add_mutually_exclusive_group()
but I don't find it trivial enough to be combined with the addition of a feature that is not really trivial either. Please use (at least) 2 separate commits.
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