Skip to content

help cmd ignores "HIdden" property #2269

Open
@duglin

Description

@duglin

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions