chore: skip completion install prompts in non-interactive shells (#14391)

This commit is contained in:
Ethan
2024-08-22 15:40:53 +10:00
committed by GitHub
parent e8c59a1d9d
commit 3514ca3476
4 changed files with 14 additions and 6 deletions
+9 -1
View File
@@ -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",