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.
Prerequisite checklist
make fmt
on your commit series before opening this PR;Description of changes
Initially,
cmd.ParseFlags
in theAttributeFlags
method was used to associate the provided list of command-line arguments with the respectively registered flag. However,AttributeFlags
has since been modified to make this association by directly callingflag.Set
. Furthermore, callingcmd.ParseFlags
consistently had the unintended side-affect of populating initialized slice structures with duplicate values.To mitigate against double parsing, which results in duplicate values in, for example, slice types, remove this additional parsing of the flags.
We call
cmd.ParseFlags
only once after the config manager has been attributed as these values are required by subsequent context systems (e.g. logging). To prevent double parsing on the root command, setDisableFlagParsing
to true such that cobra'sExecuteContext
method does not end up calling this again on the root command.This also has the benefit of greatly simplify the code by removing the previously imported
execute
andexecuteC
to prevent internal parsing and fixing command completion and listing inherited flags.