mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-28 20:13:33 +00:00
cli: do not use interactive TUI elements when control terminal (tty) is not available (fixes #386)
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user