Skip to content

Commit a6b2d52

Browse files
committed
Consolidate non-interactive mode setting and detection.
1 parent ecffc29 commit a6b2d52

6 files changed

Lines changed: 9 additions & 19 deletions

File tree

cmd/state-installer/installer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (i *Installer) Install() (rerr error) {
5454
return errs.Wrap(err, "Could not determine if running as Windows administrator")
5555
}
5656
if isAdmin && !i.Params.isUpdate {
57-
prompter := prompt.New(i.an)
57+
prompter := prompt.New(i.out, i.an)
5858
if i.Params.nonInteractive {
5959
prompter.SetInteractive(false)
6060
}

cmd/state-remote-installer/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func main() {
116116
an = sync.New(anaConst.SrcStateRemoteInstaller, cfg, nil, out)
117117

118118
// Set up prompter
119-
prompter := prompt.New(an)
119+
prompter := prompt.New(out, an)
120120

121121
params := newParams()
122122
cmd := captain.NewCommand(

cmd/state/main.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,8 @@ func main() {
110110
// Set up our legacy outputer
111111
setPrinterColors(outFlags)
112112

113-
isInteractive := strings.ToLower(os.Getenv(constants.NonInteractiveEnvVarName)) != "true" && out.Config().Interactive
114113
// Run our main command logic, which is logic that defers to the error handling logic below
115-
err = run(os.Args, isInteractive, cfg, out)
114+
err = run(os.Args, cfg, out)
116115
if err != nil {
117116
exitCode, err = runbits_errors.ParseUserFacing(err)
118117
if err != nil {
@@ -121,7 +120,7 @@ func main() {
121120
}
122121
}
123122

124-
func run(args []string, isInteractive bool, cfg *config.Instance, out output.Outputer) (rerr error) {
123+
func run(args []string, cfg *config.Instance, out output.Outputer) (rerr error) {
125124
defer profile.Measure("main:run", time.Now())
126125

127126
// Set up profiling
@@ -224,10 +223,7 @@ func run(args []string, isInteractive bool, cfg *config.Instance, out output.Out
224223
}()
225224

226225
// Set up prompter
227-
prompter := prompt.New(an)
228-
if !isInteractive {
229-
prompter.SetInteractive(false)
230-
}
226+
prompter := prompt.New(out, an)
231227

232228
// Set up conditional, which accesses a lot of primer data
233229
sshell := subshell.New(cfg)

internal/constants/constants.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,6 @@ const OverrideSessionTokenEnvVarName = "ACTIVESTATE_OVERRIDE_SESSION_TOKEN"
118118
// UpdateTagEnvVarName
119119
const UpdateTagEnvVarName = "ACTIVESTATE_UPDATE_TAG"
120120

121-
// NonInteractiveEnvVarName is the name of the environment variable that specifies whether to run the State Tool without prompts
122-
const NonInteractiveEnvVarName = "ACTIVESTATE_NONINTERACTIVE"
123-
124121
// E2ETestEnvVarName is the name of the environment variable that specifies that we are running under E2E tests
125122
const E2ETestEnvVarName = "ACTIVESTATE_E2E_TEST"
126123

internal/prompt/prompt.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ type Prompt struct {
4646
}
4747

4848
// New creates a new prompter
49-
func New(an EventDispatcher) Prompter {
50-
return &Prompt{output.Get(), an, true, false}
49+
func New(out output.Outputer, an EventDispatcher) Prompter {
50+
return &Prompt{out, an, out.Config().Interactive, false}
5151
}
5252

5353
// IsInteractive checks if the prompts can be interactive or should just return default values

test/integration/edit_int_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ import (
88
"testing"
99
"time"
1010

11-
"github.com/ActiveState/cli/internal/testhelpers/suite"
12-
13-
"github.com/ActiveState/cli/internal/constants"
1411
"github.com/ActiveState/cli/internal/environment"
1512
"github.com/ActiveState/cli/internal/fileutils"
1613
"github.com/ActiveState/cli/internal/testhelpers/e2e"
14+
"github.com/ActiveState/cli/internal/testhelpers/suite"
1715
"github.com/ActiveState/cli/internal/testhelpers/tagsuite"
1816
"github.com/ActiveState/cli/pkg/project"
1917
)
@@ -76,9 +74,8 @@ func (suite *EditIntegrationTestSuite) TestEdit_NonInteractive() {
7674
}
7775
ts, env := suite.setup()
7876
defer ts.Close()
79-
extraEnv := e2e.OptAppendEnv(constants.NonInteractiveEnvVarName + "=true")
8077

81-
cp := ts.SpawnWithOpts(e2e.OptArgs("scripts", "edit", "test-script"), env, extraEnv)
78+
cp := ts.SpawnWithOpts(e2e.OptArgs("scripts", "edit", "test-script", "-n"), env)
8279
cp.Expect("Watching file changes")
8380
// Can't consistently get this line detected on CI
8481
cp.Expect("Script changes detected")

0 commit comments

Comments
 (0)