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

Add support for case-insensitive command names #1382

Closed
adw1n opened this issue Apr 22, 2021 · 6 comments · Fixed by #1802
Closed

Add support for case-insensitive command names #1382

adw1n opened this issue Apr 22, 2021 · 6 comments · Fixed by #1802
Labels
area/lib Methods and functions that exist in the cobra library and consumed by users good-first-issue Issues that a new contributor could make a PR for kind/feature A feature request for cobra; new or enhanced behavior

Comments

@adw1n
Copy link

adw1n commented Apr 22, 2021

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.

@github-actions
Copy link

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

@indianwhocodes
Copy link

indianwhocodes commented Sep 10, 2021

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

@johnSchnake
Copy link
Collaborator

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 johnSchnake added area/lib Methods and functions that exist in the cobra library and consumed by users good-first-issue Issues that a new contributor could make a PR for kind/feature A feature request for cobra; new or enhanced behavior needs PR and removed kind/stale labels Feb 16, 2022
@jpmcb jpmcb removed the needs PR label Feb 23, 2022
@trilopin
Copy link

trilopin commented Apr 8, 2022

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

@programmer04
Copy link

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

@vitaliy-ostapchuk93
Copy link

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

YuviGold added a commit to YuviGold/cobra that referenced this issue Sep 8, 2022
Add a global `EnableCaseInsensitive` variable to allow
case-insensitive command names.

The variable supports commands names and aliases globally.

Resolves spf13#1382
YuviGold added a commit to YuviGold/cobra that referenced this issue Sep 8, 2022
Add a global `EnableCaseInsensitive` variable to allow
case-insensitive command names.

The variable supports commands names and aliases globally.

Resolves spf13#1382
YuviGold added a commit to YuviGold/cobra that referenced this issue Sep 10, 2022
Add a global `EnableCaseInsensitive` variable to allow
case-insensitive command names.

The variable supports commands names and aliases globally.

Resolves spf13#1382
YuviGold added a commit to YuviGold/cobra that referenced this issue Sep 11, 2022
Add a global `EnableCaseInsensitive` variable to allow
case-insensitive command names.

The variable supports commands names and aliases globally.

Resolves spf13#1382
marckhouzam pushed a commit that referenced this issue Sep 11, 2022
Add a global `EnableCaseInsensitive` variable to allow
case-insensitive command names.

The variable supports commands names and aliases globally.

Resolves #1382
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/lib Methods and functions that exist in the cobra library and consumed by users good-first-issue Issues that a new contributor could make a PR for kind/feature A feature request for cobra; new or enhanced behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants