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
Add Active Help support #1482
Add Active Help support #1482
Conversation
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.
This is a very cool feature. Thanks for doing this.
Here is the helm branch that uses this feature: https://github.com/VilledeMontreal/helm/tree/feat/compInfo Without needing a kubernetes cluster, one can try:
I will make a smaller test program and post it in this PR. I should have thought about doing that before. |
I've just added a test program in the description of the PR which shows different Active Help scenarios and how to use the active help configuration |
@marckhouzam This is great IMO. I like the interactive nature of it and that it is opt-in. 🚀 |
I've pushed an extra commit which uses the environment variable A nice thing about using an env var is that a user could set a different active help setting for individual commands by wrapping them in an alias or script which sets the env var (although that would be a pretty advanced usage). Using a name like We could instead use the program name in the variable, something like Opinions on using a flag versus an env var? |
447ffb9
to
5e226f0
Compare
After some thought I agree with @Luap99 that it is best to use an environment variable to configure ActiveHelp. The fact that people install completion through a package manager does imply that using an env var is better to allow configuration changes to completion. The latest version of the PR uses an environment variable per program (e.g, I'll work on adding tests next. |
dcd88bf
to
d84f81f
Compare
I have added Go tests to the PR. Also, thanks to the approach of using environment variables, there is nothing special to do for the default This PR is ready for review. Thanks in advance. |
e6631ac
to
2a55698
Compare
2a55698
to
59ce7ce
Compare
3314024
to
2b81827
Compare
155729f
to
397ba6d
Compare
This PR is being marked as stale due to a long period of inactivity |
Still valid |
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 work, I really like the idea behind this.
I think it is cool to display a message when your command does not take args for example.
I tested this with bash and it works as I would expect.
func AppendActiveHelp(compArray []string, activeHelpStr string) []string { | ||
return append(compArray, fmt.Sprintf("%s%s", activeHelpMarker, activeHelpStr)) | ||
} |
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 am not sure with the API here, why do I give the compArray as parameter and get the same value with the appended entry back.
IMO It would make more sense to have it like this:
func AppendActiveHelp(activeHelpStr string) string {
return fmt.Sprintf("%s%s", activeHelpMarker, activeHelpStr)
}
and then in you code call
comps = append(comps, cobra.AppendActiveHelp("text"))
With this the caller has control over the append. While I do not think we need to worry about performance here I believe it is better when you call append only once.
text1 := cobra.AppendActiveHelp("text1")
text2 := cobra.AppendActiveHelp("text2")
comps = append(comps, text1, text2)
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 struggled to define a good API to add ActiveHelp messages. Here is how I remember choosing the AppendActiveHelp(compArray []string, activeHelpStr string)
API.
- I was worried that it was not obvious that activeHelp messages should be included in the completions array returned by
ValidArgsFunction
; the two concepts could be seen as independent by users (completions and activeHelp messages). I therefore felt that by requiring the user to specify an array (and saying in the godoc that the array should be the one also containing the completion choices) we would make it much clearer that activeHelp messages should be included in the array of completions. - based on that, I then thought we should mimic the behaviour of Go's
append()
which is why I called itAppendActiveHelp()
and required the user to assign the result to an array (just likeappend()
). All this in the hope to build on existing knowledge of an existing API.
If we end up preferring
func AppendActiveHelp(activeHelpStr string) string {
return fmt.Sprintf("%s%s", activeHelpMarker, activeHelpStr)
}
we should probably rename the method to avoid using the word "append". We could create it as CreateActiveHelpMsg()
for example.
But then I worry again that a user won't know easily what to do after having created an activeHelp message. Will they realize they must include it in the completions array?
Some people had trouble understanding what the arguments to ValidArgsFunction(cmd, args, toComplete)
represented... So I don't want to assume anything is clear 😄
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.
Hmmmmm this is a tricky one. I'm not sure on this.
I think I'm a fan of using the API presented here by Marc, but I'm warry of introducing more complexity to how users get their completions into their program.
But from my understanding of this, it's completely opt in? It's not another required step users must take to get their completions working?
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.
Correct, the existing API for normal completions is not affected at all. ActiveHelp is 100% opt-in and can be completely ignored by programs using Cobra.
I expect the most common use of ActiveHelp will/should be to display a message when there are no completions suggested. When there are no completions, the user doesn't really know what to do, so an ActiveHelp message can explain (e.g., "This command does not take any more arguments", or "Please specify a name for the container that will be created").
Thanks for trying it out! |
I've created a draft PR for the cobra-cli that uses ActiveHelp. I hope this show very easily how the feature can be used: spf13/cobra-cli#24 @johnSchnake I've spoken to others about this but not to you. I'd love your impressions on the feature. |
Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
9dc2b50
to
1db55ea
Compare
This PR exceeds the recommended size of 200 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size. |
I've rebased this PR on top of the bash-v2 improvements that were recently merged. It is ready again. @scop if you have a moment, maybe you can have a look at the bash code modifications to see if you notice anything wrong? |
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.
Wow this is incredible. I love it.
Overall, I think this is ready for the spring release of Cobra we'll be cutting soon. I'm not super up to date on the zsh/bash completions scripting but it appears to work as expected. I'm comfortable cutting a path release if we need to fix bugs if needed.
It is not possible to implement for fish currently.
I'm curious! Something due to fish's spec?
Thanks for trying this out @jpmcb 🎉
From what I remember of fish completion logic, there is no way to output something else than actual completions (can't generically print to stdout like bash allows); so my expectation is that ActiveHelp would be treated as a real completion and get sorted within the list of completions and would even be selectable as a completion through repeated TABing. So it wouldn't work as we would need. Maybe @krobelus can confirm or correct this belief. BTW, since I first opened the PR I took the time to try ActiveHelp with PowerShell and there too it is not possible to output anything else than actual completions (cannot print to stdout like bash allows). I may have an idea to hack something that may work but it would need more investigation that I haven't had time to dive deeper into. So for now, we would have to contend with bash and zsh (which until recently were pretty much the only two shells we supported anyway). |
I think this is good to merge and we can iterate as we get community feedback! Thoughts @marckhouzam? 🚀 |
yeah, fish will likely overwrite that with the completion pager. I guess we can an API for adding arbitrary text. |
Let's do it! Thanks @jpmcb 🚀 |
Skimmed it real quick and didn't notice anything wrong. There's some room for cleanups along the lines of #1702, which I suppose we should amend to cover the things added here. But the feature looks quite interesting indeed 👍 |
[](https://renovatebot.com) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [github.com/golang-jwt/jwt/v4](https://togithub.com/golang-jwt/jwt) | require | patch | `v4.4.1` -> `v4.4.2` | | [github.com/spf13/cobra](https://togithub.com/spf13/cobra) | require | minor | `v1.4.0` -> `v1.5.0` | | [github.com/stretchr/testify](https://togithub.com/stretchr/testify) | require | patch | `v1.7.2` -> `v1.7.5` | --- ### Release Notes <details> <summary>golang-jwt/jwt</summary> ### [`v4.4.2`](https://togithub.com/golang-jwt/jwt/releases/tag/v4.4.2) [Compare Source](https://togithub.com/golang-jwt/jwt/compare/v4.4.1...v4.4.2) #### What's Changed - Added MicahParks/keyfunc to extensions by [@​oxisto](https://togithub.com/oxisto) in [golang-jwt/jwt#194 - Update link to v4 on pkg.go.dev page by [@​polRk](https://togithub.com/polRk) in [golang-jwt/jwt#195 - add installation guidelines to the README file by [@​morelmiles](https://togithub.com/morelmiles) in [golang-jwt/jwt#204 - chore: replace ioutil with io and os by [@​estensen](https://togithub.com/estensen) in [golang-jwt/jwt#198 - CI check for Go code formatting by [@​mfridman](https://togithub.com/mfridman) in [golang-jwt/jwt#206 - Create SECURITY.md by [@​mfridman](https://togithub.com/mfridman) in [golang-jwt/jwt#171 - Update SECURITY.md by [@​oxisto](https://togithub.com/oxisto) in [golang-jwt/jwt#207 - Fixed integer overflow in NumericDate.MarshalJSON by [@​qqiao](https://togithub.com/qqiao) in [golang-jwt/jwt#200 - Claims in rsa_test.go Table Driven Test are Unused by [@​gkech](https://togithub.com/gkech) in [golang-jwt/jwt#212 #### New Contributors - [@​polRk](https://togithub.com/polRk) made their first contribution in [golang-jwt/jwt#195 - [@​morelmiles](https://togithub.com/morelmiles) made their first contribution in [golang-jwt/jwt#204 - [@​estensen](https://togithub.com/estensen) made their first contribution in [golang-jwt/jwt#198 - [@​qqiao](https://togithub.com/qqiao) made their first contribution in [golang-jwt/jwt#200 - [@​gkech](https://togithub.com/gkech) made their first contribution in [golang-jwt/jwt#212 **Full Changelog**: golang-jwt/jwt@v4.4.1...v4.4.2 </details> <details> <summary>spf13/cobra</summary> ### [`v1.5.0`](https://togithub.com/spf13/cobra/releases/tag/v1.5.0) [Compare Source](https://togithub.com/spf13/cobra/compare/v1.4.0...v1.5.0) #### Spring 2022 Release 🌥️ Hello everyone! Welcome to another release of cobra. Completions continue to get better and better. This release adds a few really cool new features. We also continue to patch versions of our dependencies as they become available via dependabot. Happy coding! #### Active help 👐🏼 Shout out to [@​marckhouzam](https://togithub.com/marckhouzam) for a big value add: Active Help [spf13/cobra#1482. With active help, a program can provide some inline warnings or hints for users as they hit tab. Now, your CLIs can be even more intuitive to use! Currently active help is only supported for bash V2 and zsh. Marc wrote a whole guide on how to do this, so make sure to give it a good read to learn how you can add this to your cobra code! https://github.com/spf13/cobra/blob/master/active_help.md #### Group flags 🧑🏼🤝🧑🏼 Cobra now has the ability to mark flags as required or exclusive as a ***group***. Shout out to our newest maintainer [@​johnSchnake](https://togithub.com/johnSchnake) for this! [spf13/cobra#1654 Let's say you have a `username` flag that ***MUST*** be partnered with a `password` flag. Well, now, you can enforce those as being required together: ```go rootCmd.Flags().StringVarP(&u, "username", "u", "", "Username (required if password is set)") rootCmd.Flags().StringVarP(&pw, "password", "p", "", "Password (required if username is set)") rootCmd.MarkFlagsRequiredTogether("username", "password") ``` Flags may also be marked as "mutally exclusive" with the `MarkFlagsMutuallyExclusive(string, string ... )` command API. Refer to our [user guide documentation](https://togithub.com/spf13/cobra/blob/master/user_guide.md) for further info! #### Completions 👀 - Add backwards-compatibility tests for legacyArgs() by [@​marckhouzam](https://togithub.com/marckhouzam) in [spf13/cobra#1547 - feat: Add how to load completions in your current zsh session by [@​ondrejsika](https://togithub.com/ondrejsika) in [spf13/cobra#1608 - Introduce FixedCompletions by [@​emersion](https://togithub.com/emersion) in [spf13/cobra#1574 - Add shell completion to flag groups by [@​marckhouzam](https://togithub.com/marckhouzam) in [spf13/cobra#1659 - Modify brew prefix path in macOS system by [@​imxw](https://togithub.com/imxw) in [spf13/cobra#1719 - perf(bash-v2): use backslash escape string expansion for tab by [@​scop](https://togithub.com/scop) in [spf13/cobra#1682 - style(bash-v2): out is not an array variable, do not refer to it as such by [@​scop](https://togithub.com/scop) in [spf13/cobra#1681 - perf(bash-v2): standard completion optimizations by [@​scop](https://togithub.com/scop) in [spf13/cobra#1683 - style(bash): out is not an array variable, do not refer to it as such by [@​scop](https://togithub.com/scop) in [spf13/cobra#1684 - perf(bash-v2): short-circuit descriptionless candidate lists by [@​scop](https://togithub.com/scop) in [spf13/cobra#1686 - perf(bash-v2): speed up filtering entries with descriptions by [@​scop](https://togithub.com/scop) in [spf13/cobra#1689 - perf(bash-v2): speed up filtering menu-complete descriptions by [@​scop](https://togithub.com/scop) in [spf13/cobra#1692 - fix(bash-v2): skip empty completions when filtering descriptions by [@​scop](https://togithub.com/scop) in [spf13/cobra#1691 - perf(bash-v2): read directly to COMPREPLY on descriptionless short circuit by [@​scop](https://togithub.com/scop) in [spf13/cobra#1700 - fix: Don't complete \_command on zsh by [@​twpayne](https://togithub.com/twpayne) in [spf13/cobra#1690 - Improve fish_completions code quality by [@​t29kida](https://togithub.com/t29kida) in [spf13/cobra#1515 - Fix handling of descriptions for bash v3 by [@​marckhouzam](https://togithub.com/marckhouzam) in [spf13/cobra#1735 - undefined or nil Args default to ArbitraryArgs by [@​umarcor](https://togithub.com/umarcor) in [spf13/cobra#1612 - Add Command.SetContext by [@​joshcarp](https://togithub.com/joshcarp) in [spf13/cobra#1551 - Wrap printf tab with quotes by [@​PapaCharlie](https://togithub.com/PapaCharlie) in [spf13/cobra#1665 #### Documentation 📝 - Fixed typos in completions docs - [@​cuishuang](https://togithub.com/cuishuang) [spf13/cobra#1625 - Removed `CHANGELOG.md` as it isn't updated - [@​johnSchnake](https://togithub.com/johnSchnake) [spf13/cobra#1634 - Minor typo fix in `shell_completion.md` - [@​danieldn](https://togithub.com/danieldn) [spf13/cobra#1678 - Changed branch name in the cobra generator link to 'main' - [@​skywalker2909](https://togithub.com/skywalker2909) [spf13/cobra#1645 - Fix Command.Context comment by [@​katexochen](https://togithub.com/katexochen) in [spf13/cobra#1639 - Change appropriate links from http:// to https:// where applicable - [@​deining](https://togithub.com/deining) [spf13/cobra#1695 #### Testing & CI ⚙️ - Test on Golang 1.18 - [@​umarcor](https://togithub.com/umarcor) [spf13/cobra#1635 - Use `RICHGO_FORCE_COLOR` - [@​umarcor](https://togithub.com/umarcor) [spf13/cobra#1647 - Adds size labeler GitHub action by [@​jpmcb](https://togithub.com/jpmcb) in [spf13/cobra#1610 - Update `stale-bot` settings - [@​jpmcb](https://togithub.com/jpmcb) [spf13/cobra#1609 #### Beep boop, bot commits 🤖 - Bumped golangci/golangci-lint-action from 3.1.0 to 3.2.0 - [@​dependabot](https://togithub.com/dependabot) [spf13/cobra#1697 - Bump codelytv/pr-size-labeler from 1.8.0 to 1.8.1 - [@​dependabot](https://togithub.com/dependabot) [spf13/cobra#1661 - Bump actions/stale from 1 to 5 by [@​dependabot](https://togithub.com/dependabot) in [spf13/cobra#1618 - Bump actions/cache from 2 to 3 by [@​dependabot](https://togithub.com/dependabot) in [spf13/cobra#1640 - Bump actions/labeler from 3 to 4 by [@​dependabot](https://togithub.com/dependabot) in [spf13/cobra#1620 - Bump golangci/golangci-lint-action from 2 to 3.1.0 by [@​dependabot](https://togithub.com/dependabot) in [spf13/cobra#1615 - Bump actions/checkout from 2 to 3 by [@​dependabot](https://togithub.com/dependabot) in [spf13/cobra#1619 - Bump github.com/cpuguy83/go-md2man/v2 from 2.0.1 to 2.0.2 by [@​dependabot](https://togithub.com/dependabot) in [spf13/cobra#1688 - Bump actions/setup-go from 2 to 3 by [@​dependabot](https://togithub.com/dependabot) in [spf13/cobra#1660 #### Misc 💭 - Use `errors.Is()` to check for errors - [@​Luap99](https://togithub.com/Luap99) [spf13/cobra#1730 - Prefer ReplaceAll instead of Replace(..., -1) by [@​WhyNotHugo](https://togithub.com/WhyNotHugo) in [spf13/cobra#1530 - Add Kubescape to projects - [@​avinashupadhya99](https://togithub.com/avinashupadhya99) [spf13/cobra#1642 - Add Pulumi as a project using cobra by [@​iwahbe](https://togithub.com/iwahbe) in [spf13/cobra#1720 - Add Polygon Edge as a project using Cobra by [@​zivkovicmilos](https://togithub.com/zivkovicmilos) in [spf13/cobra#1672 Shoutout to *ALL* our contributors (and all the new first time contributors!!) - great work everyone!! Cobra and it's huge impact wouldn't be possible without you 👏🏼 🚀 🐍 **Full Changelog**: spf13/cobra@v1.4.0...v1.5.0 </details> <details> <summary>stretchr/testify</summary> ### [`v1.7.5`](https://togithub.com/stretchr/testify/compare/v1.7.4...v1.7.5) [Compare Source](https://togithub.com/stretchr/testify/compare/v1.7.4...v1.7.5) ### [`v1.7.4`](https://togithub.com/stretchr/testify/compare/v1.7.3...v1.7.4) [Compare Source](https://togithub.com/stretchr/testify/compare/v1.7.3...v1.7.4) ### [`v1.7.3`](https://togithub.com/stretchr/testify/compare/v1.7.2...v1.7.3) [Compare Source](https://togithub.com/stretchr/testify/compare/v1.7.2...v1.7.3) </details> --- ### Configuration 📅 **Schedule**: Branch creation - "before 5am on Thursday" in timezone America/New_York, Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://togithub.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.
[](https://renovatebot.com) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [github.com/spf13/cobra](https://togithub.com/spf13/cobra) | require | minor | `v1.4.0` -> `v1.5.0` | --- ### Release Notes <details> <summary>spf13/cobra</summary> ### [`v1.5.0`](https://togithub.com/spf13/cobra/releases/tag/v1.5.0) [Compare Source](https://togithub.com/spf13/cobra/compare/v1.4.0...v1.5.0) #### Spring 2022 Release 🌥️ Hello everyone! Welcome to another release of cobra. Completions continue to get better and better. This release adds a few really cool new features. We also continue to patch versions of our dependencies as they become available via dependabot. Happy coding! #### Active help 👐🏼 Shout out to [@​marckhouzam](https://togithub.com/marckhouzam) for a big value add: Active Help [spf13/cobra#1482. With active help, a program can provide some inline warnings or hints for users as they hit tab. Now, your CLIs can be even more intuitive to use! Currently active help is only supported for bash V2 and zsh. Marc wrote a whole guide on how to do this, so make sure to give it a good read to learn how you can add this to your cobra code! https://github.com/spf13/cobra/blob/master/active_help.md #### Group flags 🧑🏼🤝🧑🏼 Cobra now has the ability to mark flags as required or exclusive as a ***group***. Shout out to our newest maintainer [@​johnSchnake](https://togithub.com/johnSchnake) for this! [spf13/cobra#1654 Let's say you have a `username` flag that ***MUST*** be partnered with a `password` flag. Well, now, you can enforce those as being required together: ```go rootCmd.Flags().StringVarP(&u, "username", "u", "", "Username (required if password is set)") rootCmd.Flags().StringVarP(&pw, "password", "p", "", "Password (required if username is set)") rootCmd.MarkFlagsRequiredTogether("username", "password") ``` Flags may also be marked as "mutally exclusive" with the `MarkFlagsMutuallyExclusive(string, string ... )` command API. Refer to our [user guide documentation](https://togithub.com/spf13/cobra/blob/master/user_guide.md) for further info! #### Completions 👀 - Add backwards-compatibility tests for legacyArgs() by [@​marckhouzam](https://togithub.com/marckhouzam) in [spf13/cobra#1547 - feat: Add how to load completions in your current zsh session by [@​ondrejsika](https://togithub.com/ondrejsika) in [spf13/cobra#1608 - Introduce FixedCompletions by [@​emersion](https://togithub.com/emersion) in [spf13/cobra#1574 - Add shell completion to flag groups by [@​marckhouzam](https://togithub.com/marckhouzam) in [spf13/cobra#1659 - Modify brew prefix path in macOS system by [@​imxw](https://togithub.com/imxw) in [spf13/cobra#1719 - perf(bash-v2): use backslash escape string expansion for tab by [@​scop](https://togithub.com/scop) in [spf13/cobra#1682 - style(bash-v2): out is not an array variable, do not refer to it as such by [@​scop](https://togithub.com/scop) in [spf13/cobra#1681 - perf(bash-v2): standard completion optimizations by [@​scop](https://togithub.com/scop) in [spf13/cobra#1683 - style(bash): out is not an array variable, do not refer to it as such by [@​scop](https://togithub.com/scop) in [spf13/cobra#1684 - perf(bash-v2): short-circuit descriptionless candidate lists by [@​scop](https://togithub.com/scop) in [spf13/cobra#1686 - perf(bash-v2): speed up filtering entries with descriptions by [@​scop](https://togithub.com/scop) in [spf13/cobra#1689 - perf(bash-v2): speed up filtering menu-complete descriptions by [@​scop](https://togithub.com/scop) in [spf13/cobra#1692 - fix(bash-v2): skip empty completions when filtering descriptions by [@​scop](https://togithub.com/scop) in [spf13/cobra#1691 - perf(bash-v2): read directly to COMPREPLY on descriptionless short circuit by [@​scop](https://togithub.com/scop) in [spf13/cobra#1700 - fix: Don't complete \_command on zsh by [@​twpayne](https://togithub.com/twpayne) in [spf13/cobra#1690 - Improve fish_completions code quality by [@​t29kida](https://togithub.com/t29kida) in [spf13/cobra#1515 - Fix handling of descriptions for bash v3 by [@​marckhouzam](https://togithub.com/marckhouzam) in [spf13/cobra#1735 - undefined or nil Args default to ArbitraryArgs by [@​umarcor](https://togithub.com/umarcor) in [spf13/cobra#1612 - Add Command.SetContext by [@​joshcarp](https://togithub.com/joshcarp) in [spf13/cobra#1551 - Wrap printf tab with quotes by [@​PapaCharlie](https://togithub.com/PapaCharlie) in [spf13/cobra#1665 #### Documentation 📝 - Fixed typos in completions docs - [@​cuishuang](https://togithub.com/cuishuang) [spf13/cobra#1625 - Removed `CHANGELOG.md` as it isn't updated - [@​johnSchnake](https://togithub.com/johnSchnake) [spf13/cobra#1634 - Minor typo fix in `shell_completion.md` - [@​danieldn](https://togithub.com/danieldn) [spf13/cobra#1678 - Changed branch name in the cobra generator link to 'main' - [@​skywalker2909](https://togithub.com/skywalker2909) [spf13/cobra#1645 - Fix Command.Context comment by [@​katexochen](https://togithub.com/katexochen) in [spf13/cobra#1639 - Change appropriate links from http:// to https:// where applicable - [@​deining](https://togithub.com/deining) [spf13/cobra#1695 #### Testing & CI ⚙️ - Test on Golang 1.18 - [@​umarcor](https://togithub.com/umarcor) [spf13/cobra#1635 - Use `RICHGO_FORCE_COLOR` - [@​umarcor](https://togithub.com/umarcor) [spf13/cobra#1647 - Adds size labeler GitHub action by [@​jpmcb](https://togithub.com/jpmcb) in [spf13/cobra#1610 - Update `stale-bot` settings - [@​jpmcb](https://togithub.com/jpmcb) [spf13/cobra#1609 #### Beep boop, bot commits 🤖 - Bumped golangci/golangci-lint-action from 3.1.0 to 3.2.0 - [@​dependabot](https://togithub.com/dependabot) [spf13/cobra#1697 - Bump codelytv/pr-size-labeler from 1.8.0 to 1.8.1 - [@​dependabot](https://togithub.com/dependabot) [spf13/cobra#1661 - Bump actions/stale from 1 to 5 by [@​dependabot](https://togithub.com/dependabot) in [spf13/cobra#1618 - Bump actions/cache from 2 to 3 by [@​dependabot](https://togithub.com/dependabot) in [spf13/cobra#1640 - Bump actions/labeler from 3 to 4 by [@​dependabot](https://togithub.com/dependabot) in [spf13/cobra#1620 - Bump golangci/golangci-lint-action from 2 to 3.1.0 by [@​dependabot](https://togithub.com/dependabot) in [spf13/cobra#1615 - Bump actions/checkout from 2 to 3 by [@​dependabot](https://togithub.com/dependabot) in [spf13/cobra#1619 - Bump github.com/cpuguy83/go-md2man/v2 from 2.0.1 to 2.0.2 by [@​dependabot](https://togithub.com/dependabot) in [spf13/cobra#1688 - Bump actions/setup-go from 2 to 3 by [@​dependabot](https://togithub.com/dependabot) in [spf13/cobra#1660 #### Misc 💭 - Use `errors.Is()` to check for errors - [@​Luap99](https://togithub.com/Luap99) [spf13/cobra#1730 - Prefer ReplaceAll instead of Replace(..., -1) by [@​WhyNotHugo](https://togithub.com/WhyNotHugo) in [spf13/cobra#1530 - Add Kubescape to projects - [@​avinashupadhya99](https://togithub.com/avinashupadhya99) [spf13/cobra#1642 - Add Pulumi as a project using cobra by [@​iwahbe](https://togithub.com/iwahbe) in [spf13/cobra#1720 - Add Polygon Edge as a project using Cobra by [@​zivkovicmilos](https://togithub.com/zivkovicmilos) in [spf13/cobra#1672 Shoutout to *ALL* our contributors (and all the new first time contributors!!) - great work everyone!! Cobra and it's huge impact wouldn't be possible without you 👏🏼 🚀 🐍 **Full Changelog**: spf13/cobra@v1.4.0...v1.5.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox. --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/gapic-showcase).
This PR is a proposal to enhance the shell completion logic with a framework for what I call "Active Help".
Active Help are messages (hints, warnings, etc) that are printed during the use of the program using the shell completion system. It aims to help teach how to use the program in an "active" fashion.
For example,
Active Help messages are defined by the program by adding them as custom completions using
ValidArgsFunction
andRegisterFlagCompletionFunc
and a new function:cobra.AppendActiveHelp(completionArray, activeHelpMessage)
.Here is a 3 minute video illustrating how the feature can be used:
The PR contains documentation describing how to use the feature.
The PR adds the feature to both
bash
andzsh
.It is probably do-able for. It is not possible to implement forpowershell
but I haven't triedpowrshell
orfish
currently.I'd be interested to know if this is something of interest to the community.
Note:
For bash, version >= 4.4 of bash provides a smoother experience. In older versions of bash, when printing Active Help, the prompt will not be shown before what the user has typed, but will re-appear when normal completion is triggered. For example:
Should Active Help be disabled completely for bash < 4.4, or is the lack of prompt acceptable?
Missing:
This can be seen in action using spf13/cobra-cli#24
Here is a test program that adds some active help:
Test program
/cc @jpmcb @jharshman @Luap99