Skip to content

Commit

Permalink
Autocomplete: register non hidden aliases even if the command is hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
tucksaun committed Jun 14, 2024
1 parent f275e4c commit e070c91
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
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

0 comments on commit e070c91

Please sign in to comment.