Repository navigation
cmd/root: Replace the usage function with a template - #775
Closed
martymichal wants to merge 1 commit into
Closed
martymichal wants to merge 1 commit into
martymichal wants to merge 1 commit into
Conversation
Templates are more dynamic when it comes to context switched. The usage recognizes as a different context every command/subcommand. Instead of suggesting: "Run 'toolbox --help' for usage." for every command, it makes more sense to suggest: "Run 'toolbox <command> --help.". This can be achieved either by setting a specific function for every command, setting a function that gathers all the necessary info or by using a template string. This implements the third approach. The approach causes the loss of specific binary in cases when the binary has been renamed from "toolbox" to something else because the template relies on data provided to Cobra, the CLI framework. To me this seems like an acceptable trade-off because we never allowed renaming of the binary anyway. To make use of this in all other command, all lines with: "Run 'toolbox --help' for usage." will have to be replaced with cmd.UsageString() or an analogous function working with the usage string. This is problematic since this requires access to the cmd variable (cobra.Command) which is not possible in all cases in cmd/enter.go and cmd/run.go. These functions will have to be refactored to make use of this.
|
Build succeeded.
|
This was referenced Jun 22, 2021
Member
Author
|
Before this can be merged some test cases have to be written to make sure the behaviour is correct. |
Member
Author
|
Superseded by #917. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Templates are more dynamic when it comes to context switched. The usage
recognizes as a different context every command/subcommand. Instead of
suggesting:
"Run 'toolbox --help' for usage."
for every command, it makes more sense to suggest:
"Run 'toolbox --help.".
This can be achieved either by setting a specific function for every
command, setting a function that gathers all the necessary info or by
using a template string. This implements the third approach.
The approach causes the loss of specific binary in cases when the binary
has been renamed from "toolbox" to something else because the template
relies on data provided to Cobra, the CLI framework. To me this seems
like an acceptable trade-off because we never allowed renaming of the
binary anyway.
To make use of this in all other command, all lines with:
"Run 'toolbox --help' for usage."
will have to be replaced with cmd.UsageString() or an analogous function
working with the usage string. This is problematic since this requires
access to the cmd variable (cobra.Command) which is not possible in all
cases in cmd/enter.go and cmd/run.go. These functions will have to be
refactored to make use of this.