cobra icon indicating copy to clipboard operation
cobra copied to clipboard

Add support for case-insensitive command names

Open adw1n opened this issue 3 years ago • 6 comments

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.

adw1n avatar Apr 22 '21 10:04 adw1n

This issue is being marked as stale due to a long period of inactivity

github-actions[bot] avatar Jun 22 '21 00:06 github-actions[bot]

Is this issue planned on being addressed to anytime soon in any of the subsequent releases ?

indianwhocodes avatar Sep 10 '21 19:09 indianwhocodes

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.

johnSchnake avatar Feb 16 '22 19:02 johnSchnake

Hi, I would want to help with this one. Is it still a desired enhancement? is anyone already working on it?

trilopin avatar Apr 08 '22 08:04 trilopin

I'd like to see something like this. Let's go for it @trilopin, I can help if you need

programmer04 avatar Apr 08 '22 08:04 programmer04

Would love to see this feature! If still open, I would offer to help out?

vitaliy-ostapchuk93 avatar Jun 27 '22 16:06 vitaliy-ostapchuk93