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

Autocomplete: register non hidden aliases even if the command is hidden #17

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ type Command struct {
HelpName string
// The name used on the CLI by the user
UserName string

commandNamePath []string
}

func Hide() bool {
Expand All @@ -81,9 +79,6 @@ func Hide() bool {
// FullName returns the full name of the command.
// For subcommands this ensures that parent commands are part of the command path
func (c *Command) FullName() string {
if c.commandNamePath != nil {
return strings.Join(c.commandNamePath, " ")
}
if c.Category != "" {
return strings.Join([]string{c.Category, c.Name}, ":")
}
Expand Down Expand Up @@ -164,12 +159,8 @@ func (c *Command) Run(ctx *Context) (err error) {

// Names returns the names including short names and aliases.
func (c *Command) Names() []string {
name := c.Name
if c.Category != "" {
name = c.Category + ":" + name
}
names := []string{}
if name != "" {
if name := c.FullName(); name != "" {
names = append(names, name)
}
for _, a := range c.Aliases {
Expand Down
11 changes: 8 additions & 3 deletions completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,16 @@ func AutocompleteAppAction(c *Context) error {
}

// transpose registered commands and flags to posener/complete equivalence
for _, command := range c.App.VisibleCommands() {
for _, command := range c.App.Commands {
subCmd := command.convertToPosenerCompleteCommand(c)

for _, name := range command.Names() {
cmd.Sub[name] = subCmd
if command.Hidden == nil || !command.Hidden() {
cmd.Sub[command.FullName()] = subCmd
}
for _, alias := range command.Aliases {
if !alias.Hidden {
cmd.Sub[alias.String()] = subCmd
}
}
}

Expand Down
Loading