-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLI: allow setting options for config without profiles (#5544)
The `verdi config set` command would except if the config had no configured profiles. The reason is that the command would attempt to retrieve the `Config` instance from the `ctx.obj` object. The problem is however that this is created and set on the context in the `convert` method of the `ProfileParamType`, which is used for the `--profile` option. The option specifies a default, which is the default profile, but if that is not defined, it doesn't provide anything and so the `convert` method is never called, resulting in the `ctx.obj` never being initialized and the `config` not being set. Since the config should always be present for all `verdi` comments, we should ensure that it is always loaded and set on `ctx.obj`. Therefore it is removed from `ProfileParamType.convert` and added to the constructor of a custom implementation of the `click.Context` class, called `VerdiContext`. The `VerdiCommandGroup` is updated to set the `context_class` attribute to this `VerdiContext` which will ensure that all commands will be invoked using a context that has the user defined object constructed with the config loaded and added to it. Since all commands in `verdi` will implement this class, this should guarantee that the config will always be initialized.
- Loading branch information
Showing
5 changed files
with
169 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters