@@ -14,42 +14,42 @@ const (
14
14
completionFlag = "--generate-shell-completion"
15
15
)
16
16
17
- type renderCompletion func (cmd * Command , appName string ) (string , error )
17
+ type renderCompletion func (cmd * Command ) (string , error )
18
18
19
19
var (
20
20
//go:embed autocomplete
21
21
autoCompleteFS embed.FS
22
22
23
23
shellCompletions = map [string ]renderCompletion {
24
- "bash" : func (c * Command , appName string ) (string , error ) {
24
+ "bash" : func (c * Command ) (string , error ) {
25
25
b , err := autoCompleteFS .ReadFile ("autocomplete/bash_autocomplete" )
26
- return fmt .Sprintf (string (b ), appName ), err
26
+ return fmt .Sprintf (string (b ), c . Name ), err
27
27
},
28
- "zsh" : func (c * Command , appName string ) (string , error ) {
28
+ "zsh" : func (c * Command ) (string , error ) {
29
29
b , err := autoCompleteFS .ReadFile ("autocomplete/zsh_autocomplete" )
30
- return fmt .Sprintf (string (b ), appName ), err
30
+ return fmt .Sprintf (string (b ), c . Name ), err
31
31
},
32
- "fish" : func (c * Command , appName string ) (string , error ) {
32
+ "fish" : func (c * Command ) (string , error ) {
33
33
return c .ToFishCompletion ()
34
34
},
35
- "pwsh" : func (c * Command , appName string ) (string , error ) {
35
+ "pwsh" : func (c * Command ) (string , error ) {
36
36
b , err := autoCompleteFS .ReadFile ("autocomplete/powershell_autocomplete.ps1" )
37
37
return string (b ), err
38
38
},
39
39
}
40
40
)
41
41
42
- func buildCompletionCommand (appName string ) * Command {
42
+ func buildCompletionCommand (rootCmd * Command ) * Command {
43
43
return & Command {
44
44
Name : completionCommandName ,
45
45
Hidden : true ,
46
46
Action : func (ctx context.Context , cmd * Command ) error {
47
- return printShellCompletion (ctx , cmd , appName )
47
+ return printShellCompletion (ctx , cmd , rootCmd )
48
48
},
49
49
}
50
50
}
51
51
52
- func printShellCompletion (_ context.Context , cmd * Command , appName string ) error {
52
+ func printShellCompletion (_ context.Context , cmd * Command , rootCmd * Command ) error {
53
53
var shells []string
54
54
for k := range shellCompletions {
55
55
shells = append (shells , k )
@@ -67,7 +67,7 @@ func printShellCompletion(_ context.Context, cmd *Command, appName string) error
67
67
return Exit (fmt .Sprintf ("unknown shell %s, available shells are %+v" , s , shells ), 1 )
68
68
}
69
69
70
- completionScript , err := renderCompletion (cmd , appName )
70
+ completionScript , err := renderCompletion (rootCmd )
71
71
if err != nil {
72
72
return Exit (err , 1 )
73
73
}
0 commit comments