Skip to content
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

Inconsistent program name in --help message #521

Closed
ahmetb opened this issue Feb 28, 2020 · 17 comments · Fixed by #547
Closed

Inconsistent program name in --help message #521

ahmetb opened this issue Feb 28, 2020 · 17 comments · Fixed by #547
Assignees
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.

Comments

@ahmetb
Copy link
Member

ahmetb commented Feb 28, 2020

See the end, it doesn't say kubectl krew

$ kubectl krew
[...]
Flags:
  -h, --help      help for krew
  -v, --v Level   number for the log level verbosity

Use "krew [command] --help" for more information about a command.
@ahmetb ahmetb added help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. labels Feb 28, 2020
@aimbot31
Copy link
Contributor

aimbot31 commented Mar 6, 2020

Hi @ahmetb would love to help on this one !

@aimbot31
Copy link
Contributor

aimbot31 commented Mar 6, 2020

After some researches I've found that we cannot change this behaviour.
However, we can use the Aliases field to print the fact that you can do krew and kubectl krew.
I've tried to use template but this seems a little bit overkill for the need.

Here is the result with the Aliases field :

krew is the kubectl plugin manager.
You can invoke krew through kubectl: "kubectl krew [command]..."

Usage:
  krew [command]

Aliases:
  krew, kubectl krew

Available Commands:
  help        Help about any command
  info        Show information about a kubectl plugin
  install     Install kubectl plugins
  list        List installed kubectl plugins
  search      Discover kubectl plugins
  uninstall   Uninstall plugins
  update      Update the local copy of the plugin index
  upgrade     Upgrade installed plugins to newer versions
  version     Show krew version and diagnostics

Flags:
  -h, --help      help for krew
  -v, --v Level   number for the log level verbosity

Use "krew [command] --help" for more information about a command.

@ahmetb
Copy link
Member Author

ahmetb commented Mar 6, 2020

I think that makes the situation worse, and doesn't solve any of the existing occurrences. Isn't there a Name field?

@aimbot31
Copy link
Contributor

aimbot31 commented Mar 6, 2020

There's a field "Use" but if we enter a space in this field, it will only take the first name.
For example: Use: "kubectl krew" will give :

Use "kubectl [command] --help" for more information about a command.

@ahmetb
Copy link
Member Author

ahmetb commented Mar 6, 2020

Hmm I suspect that might be a bug in cobra. (It would be good to follow up with them). Alternatively, we can consider nbsp character to prevent splitting, but it's hacky.

@aimbot31
Copy link
Contributor

aimbot31 commented Mar 6, 2020

Do you want me to try something with nbsp and place an issue to cobra repository ?

@ahmetb
Copy link
Member Author

ahmetb commented Mar 6, 2020

Let's ask cobra repo first since this is not urgent. Maybe they have a solution. I also recommend looking at cobra code to see where/why the splitting happens. Maybe there's a way to disable it.

@brianpursley
Copy link
Member

brianpursley commented Mar 10, 2020

Has anyone asked cobra yet?

I worked up a little example that I think illustrates the problem from cobra's perspective:

main.go

package main

import (
	"github.com/spf13/cobra"
)

func main() {
	var rootCmd = &cobra.Command{
		Use: "kubectl myplugin",
	}

	rootCmd.AddCommand(&cobra.Command{
		Use: "dosomething",
		Run: func(cmd *cobra.Command, args []string) {
		},
	})

	_ = rootCmd.Execute()
}

Default help for root command when running without a command:

go run main.go
Usage:
  kubectl [command]

Available Commands:
  dosomething 
  help        Help about any command

Flags:
  -h, --help   help for kubectl

Use "kubectl [command] --help" for more information about a command.

Help for a specific command:

go run main.go dosomething --help
Usage:
  kubectl dosomething [flags]

Flags:
  -h, --help   help for dosomething

@ahmetb
Copy link
Member Author

ahmetb commented Mar 11, 2020

Don’t think anyone followed up in Hugo repo. If anyone has time to fix it in upstream, would be super appreciated. 💕

@brianpursley
Copy link
Member

brianpursley commented Mar 11, 2020

I'll take a look at it in the cobra repo and circle back once it is resolved to resolve this issue.

/assign

@corneliusweig
Copy link
Contributor

Cobra people are very reluctant to merge anything. I would not count on them suddenly merging a PR. See spf13/cobra#959.

@brianpursley
Copy link
Member

brianpursley commented Mar 11, 2020

@corneliusweig I noticed they have a lot of unmerged PRs, so I guess you're probably right. I did open an issue and suggest a potential PR that would allow space to be preserved if it is escaped, but I won't get my hopes up.

In the meantime, I will revisit the krew and kubectl code and see if there is a workaround.

@corneliusweig
Copy link
Contributor

Yeah, I fear we have to handle this on our side.

@brianpursley
Copy link
Member

Its ok I actually think I found a way that cobra lets us customize the usage template.... working on it now to try it out. looks promising so far.

@ahmetb
Copy link
Member Author

ahmetb commented Mar 11, 2020

I am hoping we don’t maintain a custom go template. But if we do, maybe we can simplify a few other things along the way.

@ahmetb
Copy link
Member Author

ahmetb commented Mar 11, 2020

If the patch is trivial btw I might be able to get it merged. Just let me know.

@brianpursley
Copy link
Member

OK, let me know what you think.

It's a little bit hack-y but not TOO bad 😄

#547

brianpursley added a commit to brianpursley/krew that referenced this issue Mar 12, 2020
…y 'kubectl krew' instead of just 'krew'

See issue kubernetes-sigs#521 for more details: kubernetes-sigs#521
brianpursley added a commit to brianpursley/krew that referenced this issue Mar 12, 2020
…y 'kubectl krew' instead of just 'krew'

See issue kubernetes-sigs#521 for more details: kubernetes-sigs#521
brianpursley added a commit to brianpursley/krew that referenced this issue Mar 12, 2020
…y 'kubectl krew' instead of just 'krew'

See issue kubernetes-sigs#521 for more details
brianpursley added a commit to brianpursley/krew that referenced this issue Mar 13, 2020
…y 'kubectl krew' instead of just 'krew'

See issue kubernetes-sigs#521 for more details
k8s-ci-robot pushed a commit that referenced this issue Mar 13, 2020
…y 'kubectl krew' instead of just 'krew' (#547)

See issue #521 for more details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.
Projects
None yet
4 participants