Skip to content

Commit 2418bad

Browse files
tashianclaude
andcommitted
Add --non-interactive flag and improve TTY detection
Add support for non-interactive environments by: - Adding --non-interactive global flag (also STEP_NON_INTERACTIVE env var) - Checking for terminal availability before prompting for passwords - Returning helpful error messages when prompts fail in CI/systemd/Docker This change requires smallstep/cli-utils#210 which adds: - ui.CanPrompt() for TTY detection - errs.RequiredInputError for descriptive error messages Fixes #674 Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 027220f commit 2418bad

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ require (
128128
go.opentelemetry.io/otel/metric v1.38.0 // indirect
129129
go.opentelemetry.io/otel/trace v1.38.0 // indirect
130130
go.yaml.in/yaml/v2 v2.4.2 // indirect
131-
golang.org/x/net v0.48.0 // indirect
131+
golang.org/x/net v0.49.0 // indirect
132132
golang.org/x/oauth2 v0.33.0 // indirect
133133
golang.org/x/sync v0.19.0 // indirect
134134
golang.org/x/text v0.33.0 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,8 @@ golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
402402
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
403403
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
404404
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
405-
golang.org/x/net v0.48.0 h1:zyQRTTrjc33Lhh0fBgT/H3oZq9WuvRR5gPC70xpDiQU=
406-
golang.org/x/net v0.48.0/go.mod h1:+ndRgGjkh8FGtu1w1FGbEC31if4VrNVMuKTgcAAnQRY=
405+
golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o=
406+
golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8=
407407
golang.org/x/oauth2 v0.33.0 h1:4Q+qn+E5z8gPRJfmRy7C2gGG3T4jIprK6aSYgTXGRpo=
408408
golang.org/x/oauth2 v0.33.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA=
409409
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=

internal/cmd/root.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/urfave/cli"
1414

1515
"github.com/smallstep/cli-utils/command"
16+
"github.com/smallstep/cli-utils/errs"
1617
"github.com/smallstep/cli-utils/fileutil"
1718
"github.com/smallstep/cli-utils/step"
1819
"github.com/smallstep/cli-utils/ui"
@@ -96,9 +97,15 @@ func newApp(stdout, stderr io.Writer) *cli.App {
9697
// Define default file writers and prompters for go.step.sm/crypto
9798
pemutil.WriteFile = fileutil.WriteFile
9899
pemutil.PromptPassword = func(msg string) ([]byte, error) {
100+
if !ui.CanPrompt() {
101+
return nil, errs.NewRequiredInputError("password", "password-file")
102+
}
99103
return ui.PromptPassword(msg)
100104
}
101105
jose.PromptPassword = func(msg string) ([]byte, error) {
106+
if !ui.CanPrompt() {
107+
return nil, errs.NewRequiredInputError("password", "password-file")
108+
}
102109
return ui.PromptPassword(msg)
103110
}
104111

@@ -130,6 +137,13 @@ func newApp(stdout, stderr io.Writer) *cli.App {
130137
Usage: "path to the config file to use for CLI flags",
131138
})
132139

140+
// Flag to disable interactive prompts
141+
app.Flags = append(app.Flags, cli.BoolFlag{
142+
Name: "non-interactive",
143+
Usage: "disable interactive prompts; commands will fail if required input is missing",
144+
EnvVar: "STEP_NON_INTERACTIVE",
145+
})
146+
133147
// Action runs on `step` or `step <command>` if the command is not enabled.
134148
app.Action = func(ctx *cli.Context) error {
135149
args := ctx.Args()

0 commit comments

Comments
 (0)