Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc69e2c2

Browse files
committed
fixup
1 parent235f2cc commitc69e2c2

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

‎cli/completion.go

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package cli
22

33
import (
4-
"golang.org/x/xerrors"
4+
"fmt"
55

66
"github.com/coder/coder/v2/cli/cliui"
77
"github.com/coder/serpent"
@@ -31,26 +31,30 @@ func (*RootCmd) completion() *serpent.Command {
3131
},
3232
Handler:func(inv*serpent.Invocation)error {
3333
ifshellName!="" {
34-
shell:=completion.ShellByName(shellName,inv.Command.Parent.Name())
35-
ifshell==nil {
36-
returnxerrors.Errorf("unsupported shell %q",shellName)
34+
shell,err:=completion.ShellByName(shellName,inv.Command.Parent.Name())
35+
iferr!=nil {
36+
returnerr
3737
}
38+
ifprintOutput {
39+
returnshell.WriteCompletion(inv.Stdout)
40+
}
41+
returninstallCompletion(inv,shell)
42+
}
43+
shell,err:=completion.DetectUserShell(inv.Command.Parent.Name())
44+
iferr==nil {
3845
returninstallCompletion(inv,shell)
3946
}
40-
// shell, err := completion.DetectUserShell(inv.Command.Parent.Name())
41-
// if err == nil {
42-
// return installCompletion(inv, shell)
43-
// }
47+
// Silently continue to the shell selection if detecting failed.
4448
choice,err:=cliui.Select(inv, cliui.SelectOptions{
45-
Message:"Select a shell to install completion for",
49+
Message:"Select a shell to install completion for:",
4650
Options:shellOptions.Choices,
4751
})
4852
iferr!=nil {
4953
returnerr
5054
}
51-
shellChoice:=completion.ShellByName(choice,inv.Command.Parent.Name())
52-
ifshellChoice==nil {
53-
returnxerrors.Errorf("unsupported shell %q",shellName)
55+
shellChoice,err:=completion.ShellByName(choice,inv.Command.Parent.Name())
56+
iferr!=nil {
57+
returnerr
5458
}
5559
ifprintOutput {
5660
returnshellChoice.WriteCompletion(inv.Stdout)
@@ -66,13 +70,17 @@ func installCompletion(inv *serpent.Invocation, shell completion.Shell) error {
6670
// If we can't determine the install path, just print the completion script.
6771
returnshell.WriteCompletion(inv.Stdout)
6872
}
73+
action:="appending to"
74+
ifshell.UsesOwnFile() {
75+
action="creating"
76+
}
6977
choice,err:=cliui.Select(inv, cliui.SelectOptions{
7078
Options: []string{
7179
"Confirm",
7280
"Print to terminal",
7381
"Cancel",
7482
},
75-
Message:"Install completion for"+shell.Name()+" by appending to "+path+"?",
83+
Message:fmt.Sprintf("Install completion for%s by %s %s?",shell.Name(),action,path),
7684
HideSearch:true,
7785
})
7886
iferr!=nil {
@@ -81,7 +89,7 @@ func installCompletion(inv *serpent.Invocation, shell completion.Shell) error {
8189
ifchoice=="Cancel" {
8290
returnnil
8391
}
84-
ifchoice!="Print to terminal" {
92+
ifchoice=="Print to terminal" {
8593
returnshell.WriteCompletion(inv.Stdout)
8694
}
8795
returncompletion.InstallShellCompletion(shell)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp