-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Detecting and handling commands with uses / names that conflict with existing commands #2185
Comments
Hi @andyfeller ! We can compare with kubectl’s approach. kubectl also allows users to define plugins and be named whatever they want. When starting, kubectl will generate it’s native commands first then it will attempt to create a cobra command for each plugin. However it first make sure that the name of the plug-in does not already exist as a native command when looking over each plugin it found. If there’s a conflict, you can print an error message. kubectl also has a native Helm on the other hand has a richer plug-in support which can block plug-ins from being installed if the name conflicts. |
Thank you for taking the time and offering guidance, @marckhouzam! ❤ Let's see what Digging into
|
Long time supporter, first time caller! 👋 Wanted to solicit maintainers' insights into how users avoid conflicting commands. I appreciate any guidance offered! ❤
Problem
As of
v1.8.1
,Command.AddCommand(cmds ...*Command)
does not handle situations where a command added might conflict with theUse
/Name
of a previously added command, creating situations where commands can be overridden.cobra/command.go
Lines 1305 to 1332 in e94f6d0
At first glance, it seems
Command.Traverse(args []string)
could be used to detect whether a command by name was previously added, however this searches too deeply.cobra/command.go
Lines 790 to 831 in e94f6d0
This issue is aimed to understand how
spf13/cobra
expects multiple commands with overlap to behave, seeing if there are additional capabilities worth considering.Background
The GitHub CLI has a static set of core commands we support while facilitating users being able to install and use extensions built by the community. These extensions are not specially namespaced, so it is possible for someone to create an extension as the same name of the core commandset to override them during execution.
https://github.com/cli/cli/blob/192f57ef429b4e89937c87dcbd330520730d4a3a/pkg/cmd/root/root.go#L172-L177
In this situation, a workaround would be iterating over the top-level commands looking for conflicting names:
The text was updated successfully, but these errors were encountered: