Skip to content

Commit

Permalink
Make TTY output a forceable thing (#4318)
Browse files Browse the repository at this point in the history
In this change, we introduce `AZD_FORCE_TTY` as a mechanism to force TTY output behavior. We removed an environment variable `AZD_TERM_SKIP_CI_DETECT` since `AZD_FORCE_TTY` is the higher-level override.

Helps with #4311
  • Loading branch information
weikanglim authored Sep 26, 2024
1 parent 3f14b2a commit 22ef3f9
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions cli/azd/pkg/input/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,15 @@ type AskerConsole struct {
// the writer the console was constructed with, and what we reset to when SetWriter(nil) is called.
defaultWriter io.Writer
// the writer which output is written to.
writer io.Writer
formatter output.Formatter
writer io.Writer
formatter output.Formatter

// isTerminal controls whether terminal-style input/output will be used.
//
// When isTerminal is false, the following notable behaviors apply:
// - Spinner progress will be written as standard newline messages.
// - Prompting assumes a non-terminal environment, where output written and input received are machine-friendly text,
// stripped of formatting characters.
isTerminal bool
noPrompt bool
// when non nil, use this client instead of prompting ourselves on the console.
Expand Down Expand Up @@ -1056,24 +1063,15 @@ func NewConsole(
// IsTerminal returns true if the given file descriptors are attached to a terminal,
// taking into account of environment variables that force TTY behavior.
func IsTerminal(stdoutFd uintptr, stdinFd uintptr) bool {
// User override to force non-TTY behavior
if ok, _ := strconv.ParseBool(os.Getenv("AZD_DEBUG_FORCE_NO_TTY")); ok {
return false
// User override to force TTY behavior
if forceTty, err := strconv.ParseBool(os.Getenv("AZD_FORCE_TTY")); err == nil {
return forceTty
}

// By default, detect if we are running on CI and force no TTY mode if we are.
// Allow for an override if this is not desired.
shouldDetectCI := true
if strVal, has := os.LookupEnv("AZD_TERM_SKIP_CI_DETECT"); has {
skip, err := strconv.ParseBool(strVal)
if err != nil {
log.Println("AZD_TERM_SKIP_CI_DETECT is not a valid boolean value")
} else if skip {
shouldDetectCI = false
}
}

if shouldDetectCI && resource.IsRunningOnCI() {
// If this is affecting you locally while debugging on a CI machine,
// use the override AZD_FORCE_TTY=true.
if resource.IsRunningOnCI() {
return false
}

Expand Down

0 comments on commit 22ef3f9

Please sign in to comment.