Skip to content

help cmd ignores "HIdden" property #2269

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

Open
duglin opened this issue Apr 18, 2025 · 1 comment
Open

help cmd ignores "HIdden" property #2269

duglin opened this issue Apr 18, 2025 · 1 comment

Comments

@duglin
Copy link

duglin commented Apr 18, 2025

https://github.com/spf13/cobra/blob/ceb39aba25c86233e4888210c4b57cdb0a78d1e1/command.go#L1996C56-L1996C71 in particular the: subcmd.Name() == helpCommandName

Why is "help" special in that it'll ignore the Hidden property? It appears I can't hide "help" from the list of available commands because of this. Why????

Note that while I'm interested in knowing what the officially recommended way to get my desired results is (since the docs don't seem to mention it), I am honestly more interested in the design decision itself. As I see it:

  • "help" is so special to get this special treatment (by default it's a required sub-command that you can't hide) and yet the docs don't seem to mention this special-ness
  • we now have a situation where Hidden is basically ignored for the helpCmd. Yet there are ways around this (e.g. changing the usage template) so, the package has purposely decided to allow a way to get something done (hiding "help") but ONLY if you do something different from all other Commands and in the process make a flag/property (Hidden) 100% meaningless for a Command that's always there.
  • while changing the code so that Hidden is actually adhered to for the helpCmd seems like a potentially big change, the only people that would be impacted by it are those who (probably out of frustration) are currently setting Hidden to true and getting nothing out of it but really want to. I would consider it a bug in the user's code to be setting a flag that serves no purpose, so if Cobra was to change (for the better) it shouldn't actually be that big of an impact on existing code bases since they shouldn't be setting a pointless flag to begin with.
@marckhouzam
Copy link
Collaborator

Interesting.

My total guess is that it’s because I’d you don’t treat the help command special in the line you mention, then it will never be shown in the help text. If that is the case, then maybe the person who worked around this problem didn’t think about hiding the help command.

You’ll have to look at the commit introducing this problematic line to know for sure.

If you can figure out the history, it would be easy to tweak so that the help can be hidden.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants