Skip to content

Commit 051a25c

Browse files
authored
Merge pull request #17 from tucksaun/feat/autocomplete-register-non-hidden-aliases
Autocomplete: register non hidden aliases even if the command is hidden
2 parents 20a8b72 + e070c91 commit 051a25c

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

command.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ type Command struct {
7070
HelpName string
7171
// The name used on the CLI by the user
7272
UserName string
73-
74-
commandNamePath []string
7573
}
7674

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

165160
// Names returns the names including short names and aliases.
166161
func (c *Command) Names() []string {
167-
name := c.Name
168-
if c.Category != "" {
169-
name = c.Category + ":" + name
170-
}
171162
names := []string{}
172-
if name != "" {
163+
if name := c.FullName(); name != "" {
173164
names = append(names, name)
174165
}
175166
for _, a := range c.Aliases {

completion.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,16 @@ func AutocompleteAppAction(c *Context) error {
6262
}
6363

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

68-
for _, name := range command.Names() {
69-
cmd.Sub[name] = subCmd
68+
if command.Hidden == nil || !command.Hidden() {
69+
cmd.Sub[command.FullName()] = subCmd
70+
}
71+
for _, alias := range command.Aliases {
72+
if !alias.Hidden {
73+
cmd.Sub[alias.String()] = subCmd
74+
}
7075
}
7176
}
7277

0 commit comments

Comments
 (0)