cli: do not use interactive TUI elements when control terminal (tty) is not available (fixes #386)

This commit is contained in:
Pasha Sviderski
2026-06-18 18:22:48 +10:00
parent 7bb3cb9682
commit 2f717a10a7
10 changed files with 81 additions and 56 deletions
+6 -4
View File
@@ -99,14 +99,14 @@ func provisionMachine(ctx context.Context, exec sshexec.Executor, version string
}
func promptResetMachine() error {
if !tui.IsStdinTerminal() {
if !tui.IsTerminalAvailable() {
return errors.New("the remote machine is already initialised as a cluster member; " +
"cannot ask to confirm reset in non-interactive mode, " +
"use --yes flag or set UNCLOUD_AUTO_CONFIRM=true to auto-confirm")
}
fmt.Println(tui.Red.Render("The remote machine is already initialised as a cluster member. Resetting it will:\n" +
"- Remove all service containers from the machine\n" +
fmt.Fprintln(os.Stderr, tui.Red.Render("The remote machine is already initialised as a cluster member. Resetting it will:\n"+
"- Remove all service containers from the machine\n"+
"- Reset the Uncloud daemon on the machine to the uninitialised state"))
var confirm bool
@@ -119,7 +119,9 @@ func promptResetMachine() error {
Value(&confirm),
),
).WithTheme(tui.ThemeConfirmDanger()).
WithAccessible(true)
WithAccessible(true).
// Render to stderr so stdout stays clean for command output.
WithOutput(os.Stderr)
if err := form.Run(); err != nil {
return fmt.Errorf("prompt user to confirm: %w", err)
}