cobra
cobra copied to clipboard
Add support for case-insensitive command names
Right now users decide on supported command name using Command::Use
and Command::Aliases
. There is no way to tell Cobra to use case-insensitive name matching.
Cobra has SetGlobalNormalizationFunc
which can be used to achieve case-insensitive flag name matching but there is no such option for command names. Generating aliases with all possible spellings isn't an option because users would need to have a list of aliases that is 2**len(commandName)
characters long. Users aren't able to customize the Command::Find
behavior because Command::AddCommand
function takes a struct
and not an interface
.
@jpmcb @jharshman @marckhouzam are maintainers open to accepting a PR that adds functionality which allows users to create commands with case-insensitive command name matching?
Example
Imagine I'm writing a CLI program like kubectl
. I want to have get
subcommand and have service
(aliases: svc
, svcs
) and deployment
(aliases: deployments
) subcommands of get
subcommand. The sub-subcommand names should be case-insensitive similarly to like how you can do kubectl get sErvICeS
. kubectl
opted to have no subcommands after get
and instead takes the type of resource as first argument. If I wanted to have a case-insensitive service
sub-subcommand there is currently no supported way to achieve that.
This issue is being marked as stale due to a long period of inactivity
Is this issue planned on being addressed to anytime soon in any of the subsequent releases ?
Seems like a pretty straightforward, reasonable request to me. I'm currently focused on backlog cleanup but I think if you put up the PR I could find time to review it.
To be backwards compatible we just need to gate the behavior with a corresponding option.
Hi, I would want to help with this one. Is it still a desired enhancement? is anyone already working on it?
I'd like to see something like this. Let's go for it @trilopin, I can help if you need
Would love to see this feature! If still open, I would offer to help out?