internal/cli: add support to overwrite config.toml values via cli flags #1008
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
With the new-cli introduced in v0.3.0, there were 2 ways to set the configuration required to run bor. One can either do it via normal cli flags (args) or via a toml based config. Due to some restrictions, if the toml based config is provided, bor overwrites all the given cli flags (explicitly by the user) with those provided in toml config.
An ideal behaviour should in any cli application should be that explicitly provided flags should take control no matter what value is provided in the toml based config. This PR implements that. Sufficient tests have been added and existing tests have been improved to cover all cases for all data types.
The order of flag will now be as follows:
Example:
If the toml config looks something like this:
and the user runs the following command
Currently bor would set the
datadir
the value mentioned in config i.e.config_datadir
.With this PR, the value set for
datadir
would becli_datadir
.This is a breaking change as it changes the way people run their bor nodes. It mostly affects those who run a combination of both. Until now, their cli flags weren't set if config was set but now onwards, their additional flags will also be set. This might require an explicit communication to node operators.
Changes
Breaking changes
As mentioned above, it changes the way flags are parsed and handled. Cli args will overwrite config flags.
Checklist
Testing
Manual tests
Manual testing of flags with different datatypes have been carried to make sure it works for all types of values.