mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: skip completion install prompts in non-interactive shells (#14391)
This commit is contained in:
+9
-1
@@ -3,6 +3,8 @@ package cli
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/coder/coder/v2/cli/cliui"
|
||||
"github.com/coder/serpent"
|
||||
"github.com/coder/serpent/completion"
|
||||
@@ -45,7 +47,10 @@ func (*RootCmd) completion() *serpent.Command {
|
||||
if err == nil {
|
||||
return installCompletion(inv, shell)
|
||||
}
|
||||
// Silently continue to the shell selection if detecting failed.
|
||||
if !isTTYOut(inv) {
|
||||
return xerrors.New("could not detect the current shell, please specify one with --shell or run interactively")
|
||||
}
|
||||
// Silently continue to the shell selection if detecting failed in interactive mode
|
||||
choice, err := cliui.Select(inv, cliui.SelectOptions{
|
||||
Message: "Select a shell to install completion for:",
|
||||
Options: shellOptions.Choices,
|
||||
@@ -71,6 +76,9 @@ func installCompletion(inv *serpent.Invocation, shell completion.Shell) error {
|
||||
cliui.Error(inv.Stderr, fmt.Sprintf("Failed to determine completion path %v", err))
|
||||
return shell.WriteCompletion(inv.Stdout)
|
||||
}
|
||||
if !isTTYOut(inv) {
|
||||
return shell.WriteCompletion(inv.Stdout)
|
||||
}
|
||||
choice, err := cliui.Select(inv, cliui.SelectOptions{
|
||||
Options: []string{
|
||||
"Confirm",
|
||||
|
||||
Reference in New Issue
Block a user