From e070c91e3faa595af414516d937a81801e9f2587 Mon Sep 17 00:00:00 2001 From: Tugdual Saunier <tugdual.saunier@gmail.com> Date: Fri, 14 Jun 2024 18:04:33 +0200 Subject: [PATCH] Autocomplete: register non hidden aliases even if the command is hidden --- command.go | 11 +---------- completion.go | 11 ++++++++--- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/command.go b/command.go index bed3e4f..deb04f3 100644 --- a/command.go +++ b/command.go @@ -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 { @@ -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}, ":") } @@ -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 { diff --git a/completion.go b/completion.go index eee0a15..95104ea 100644 --- a/completion.go +++ b/completion.go @@ -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 + } } }