Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions cli/azd/cmd/auto_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,11 @@ func CreateGlobalFlagSet() *pflag.FlagSet {
false,
"Alias for --no-prompt.")
_ = globalFlags.MarkHidden("non-interactive")
globalFlags.Bool(
"fail-on-prompt",
false,
"Fails with an actionable error whenever a prompt is encountered, even if a default exists."+
" Implies --no-prompt.")
globalFlags.StringP(internal.EnvironmentNameFlagName, "e", "", "The name of the environment to use.")

// The telemetry system is responsible for reading these flags value and using it to configure the telemetry
Expand Down Expand Up @@ -725,10 +730,22 @@ func ParseGlobalFlags(args []string, opts *internal.GlobalCommandOptions) error
}
}

// Agent Detection: If no explicit flag or env var was set and we detect an AI coding
// agent as the caller, automatically enable no-prompt mode for non-interactive execution.
if !flagExplicitlySet && !envVarPresent && agentdetect.IsRunningInAgent() {
if boolVal, err := globalFlagSet.GetBool("fail-on-prompt"); err == nil {
opts.FailOnPrompt = boolVal
if boolVal {
// --fail-on-prompt implies --no-prompt
opts.NoPrompt = true
}
}

// Agent Detection: If --no-prompt was not explicitly set and we detect an AI coding agent
// as the caller, automatically enable fail-on-prompt mode for strict non-interactive execution.
failOnPromptFlag := globalFlagSet.Lookup("fail-on-prompt")
failOnPromptExplicitlySet := failOnPromptFlag != nil && failOnPromptFlag.Changed
if !flagExplicitlySet && !failOnPromptExplicitlySet &&
!envVarPresent && agentdetect.IsRunningInAgent() {
opts.NoPrompt = true
opts.FailOnPrompt = true
}

return nil
Expand Down
106 changes: 70 additions & 36 deletions cli/azd/cmd/auto_install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,58 +340,90 @@ func TestCheckForMatchingExtension_Unit(t *testing.T) {

func TestParseGlobalFlags_AgentDetection(t *testing.T) {
tests := []struct {
name string
args []string
envVars map[string]string
expectedNoPrompt bool
name string
args []string
envVars map[string]string
expectedNoPrompt bool
expectedFailOnPrompt bool
}{
{
name: "no agent detected, no flag",
args: []string{"up"},
envVars: map[string]string{},
expectedNoPrompt: false,
name: "no agent detected, no flag",
args: []string{"up"},
envVars: map[string]string{},
expectedNoPrompt: false,
expectedFailOnPrompt: false,
},
{
name: "agent detected via env var, no flag",
args: []string{"up"},
envVars: map[string]string{"CLAUDE_CODE": "1"},
expectedNoPrompt: true,
name: "agent detected via env var, no flag",
args: []string{"up"},
envVars: map[string]string{"CLAUDE_CODE": "1"},
expectedNoPrompt: true,
expectedFailOnPrompt: true,
},
{
name: "agent detected but --no-prompt=false explicitly set",
args: []string{"--no-prompt=false", "up"},
envVars: map[string]string{"CLAUDE_CODE": "1"},
expectedNoPrompt: false,
name: "agent detected but --no-prompt=false explicitly set",
args: []string{"--no-prompt=false", "up"},
envVars: map[string]string{"CLAUDE_CODE": "1"},
expectedNoPrompt: false,
expectedFailOnPrompt: false,
},
{
name: "agent detected but --no-prompt explicitly set true",
args: []string{"--no-prompt", "up"},
envVars: map[string]string{"GEMINI_CLI": "1"},
expectedNoPrompt: true,
name: "agent detected but --no-prompt explicitly set true",
args: []string{"--no-prompt", "up"},
envVars: map[string]string{"GEMINI_CLI": "1"},
expectedNoPrompt: true,
expectedFailOnPrompt: false,
},
{
name: "no agent, --no-prompt explicitly set",
args: []string{"--no-prompt", "deploy"},
envVars: map[string]string{},
expectedNoPrompt: true,
name: "no agent, --no-prompt explicitly set",
args: []string{"--no-prompt", "deploy"},
envVars: map[string]string{},
expectedNoPrompt: true,
expectedFailOnPrompt: false,
},
{
name: "Gemini agent detected",
args: []string{"init"},
envVars: map[string]string{"GEMINI_CLI": "1"},
expectedNoPrompt: true,
name: "Gemini agent detected",
args: []string{"init"},
envVars: map[string]string{"GEMINI_CLI": "1"},
expectedNoPrompt: true,
expectedFailOnPrompt: true,
},
{
name: "GitHub Copilot CLI agent detected",
args: []string{"deploy"},
envVars: map[string]string{"GITHUB_COPILOT_CLI": "true"},
expectedNoPrompt: true,
name: "GitHub Copilot CLI agent detected",
args: []string{"deploy"},
envVars: map[string]string{"GITHUB_COPILOT_CLI": "true"},
expectedNoPrompt: true,
expectedFailOnPrompt: true,
},
{
name: "OpenCode agent detected",
args: []string{"provision"},
envVars: map[string]string{"OPENCODE": "1"},
expectedNoPrompt: true,
name: "OpenCode agent detected",
args: []string{"provision"},
envVars: map[string]string{"OPENCODE": "1"},
expectedNoPrompt: true,
expectedFailOnPrompt: true,
},
{
name: "fail-on-prompt flag implies no-prompt",
args: []string{"--fail-on-prompt", "up"},
envVars: map[string]string{},
expectedNoPrompt: true,
expectedFailOnPrompt: true,
},
{
name: "no-prompt alone does not set fail-on-prompt",
args: []string{"--no-prompt", "up"},
envVars: map[string]string{},
expectedNoPrompt: true,
expectedFailOnPrompt: false,
},
{
name: "fail-on-prompt explicit overrides agent detection",
args: []string{"--fail-on-prompt", "up"},
envVars: map[string]string{
"CLAUDE_CODE": "1",
},
expectedNoPrompt: true,
expectedFailOnPrompt: true,
},
}

Expand Down Expand Up @@ -422,6 +454,8 @@ func TestParseGlobalFlags_AgentDetection(t *testing.T) {

assert.Equal(t, tt.expectedNoPrompt, opts.NoPrompt,
"NoPrompt should be %v for test case: %s", tt.expectedNoPrompt, tt.name)
assert.Equal(t, tt.expectedFailOnPrompt, opts.FailOnPrompt,
"FailOnPrompt should be %v for test case: %s", tt.expectedFailOnPrompt, tt.name)

// Clean up for next test
agentdetect.ResetDetection()
Expand Down
15 changes: 10 additions & 5 deletions cli/azd/cmd/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,16 @@ func registerCommonDependencies(container *ioc.NestedContainer) {
}
}

return input.NewConsole(rootOptions.NoPrompt, isTerminal, input.Writers{Output: writer}, input.ConsoleHandles{
Stdin: cmd.InOrStdin(),
Stdout: cmd.OutOrStdout(),
Stderr: cmd.ErrOrStderr(),
}, formatter, externalPromptCfg)
return input.NewConsole(
rootOptions.NoPrompt,
rootOptions.FailOnPrompt,
isTerminal,
input.Writers{Output: writer},
input.ConsoleHandles{
Stdin: cmd.InOrStdin(),
Stdout: cmd.OutOrStdout(),
Stderr: cmd.ErrOrStderr(),
}, formatter, externalPromptCfg)
})

container.MustRegisterSingleton(
Expand Down
1 change: 1 addition & 0 deletions cli/azd/cmd/external_prompt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func TestExternalPromptFromEnvironmentVariables(t *testing.T) {
// Create the console with external prompting configured
console := input.NewConsole(
rootOptions.NoPrompt,
rootOptions.FailOnPrompt,
isTerminal,
input.Writers{Output: writer},
input.ConsoleHandles{
Expand Down
5 changes: 5 additions & 0 deletions cli/azd/cmd/testdata/TestFigSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3681,6 +3681,11 @@ const completionSpec: Fig.Spec = {
},
],
},
{
name: ['--fail-on-prompt'],
description: 'Fails with an actionable error whenever a prompt is encountered, even if a default exists. Implies --no-prompt.',
isPersistent: true,
},
{
name: ['--no-prompt'],
description: 'Accepts the default value instead of prompting, or it fails if there is no default.',
Expand Down
1 change: 1 addition & 0 deletions cli/azd/cmd/testdata/TestUsage-azd-add.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Global Flags
--debug : Enables debugging and diagnostics logging.
--docs : Opens the documentation for azd add in your web browser.
-e, --environment string : The name of the environment to use.
--fail-on-prompt : Fails with an actionable error whenever a prompt is encountered, even if a default exists. Implies --no-prompt.
-h, --help : Gets help for add.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.

Expand Down
1 change: 1 addition & 0 deletions cli/azd/cmd/testdata/TestUsage-azd-ai-agent.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Global Flags
--debug : Enables debugging and diagnostics logging.
--docs : Opens the documentation for azd ai agent in your web browser.
-e, --environment string : The name of the environment to use.
--fail-on-prompt : Fails with an actionable error whenever a prompt is encountered, even if a default exists. Implies --no-prompt.
-h, --help : Gets help for agent.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.

Expand Down
1 change: 1 addition & 0 deletions cli/azd/cmd/testdata/TestUsage-azd-ai-finetuning.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Global Flags
--debug : Enables debugging and diagnostics logging.
--docs : Opens the documentation for azd ai finetuning in your web browser.
-e, --environment string : The name of the environment to use.
--fail-on-prompt : Fails with an actionable error whenever a prompt is encountered, even if a default exists. Implies --no-prompt.
-h, --help : Gets help for finetuning.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.

Expand Down
1 change: 1 addition & 0 deletions cli/azd/cmd/testdata/TestUsage-azd-ai-models.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Global Flags
--debug : Enables debugging and diagnostics logging.
--docs : Opens the documentation for azd ai models in your web browser.
-e, --environment string : The name of the environment to use.
--fail-on-prompt : Fails with an actionable error whenever a prompt is encountered, even if a default exists. Implies --no-prompt.
-h, --help : Gets help for models.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.

Expand Down
1 change: 1 addition & 0 deletions cli/azd/cmd/testdata/TestUsage-azd-ai.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Global Flags
--debug : Enables debugging and diagnostics logging.
--docs : Opens the documentation for azd ai in your web browser.
-e, --environment string : The name of the environment to use.
--fail-on-prompt : Fails with an actionable error whenever a prompt is encountered, even if a default exists. Implies --no-prompt.
-h, --help : Gets help for ai.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.

Expand Down
1 change: 1 addition & 0 deletions cli/azd/cmd/testdata/TestUsage-azd-appservice.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Global Flags
--debug : Enables debugging and diagnostics logging.
--docs : Opens the documentation for azd appservice in your web browser.
-e, --environment string : The name of the environment to use.
--fail-on-prompt : Fails with an actionable error whenever a prompt is encountered, even if a default exists. Implies --no-prompt.
-h, --help : Gets help for appservice.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.

Expand Down
1 change: 1 addition & 0 deletions cli/azd/cmd/testdata/TestUsage-azd-auth-login.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Global Flags
--debug : Enables debugging and diagnostics logging.
--docs : Opens the documentation for azd auth login in your web browser.
-e, --environment string : The name of the environment to use.
--fail-on-prompt : Fails with an actionable error whenever a prompt is encountered, even if a default exists. Implies --no-prompt.
-h, --help : Gets help for login.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.

Expand Down
1 change: 1 addition & 0 deletions cli/azd/cmd/testdata/TestUsage-azd-auth-logout.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Global Flags
--debug : Enables debugging and diagnostics logging.
--docs : Opens the documentation for azd auth logout in your web browser.
-e, --environment string : The name of the environment to use.
--fail-on-prompt : Fails with an actionable error whenever a prompt is encountered, even if a default exists. Implies --no-prompt.
-h, --help : Gets help for logout.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.

Expand Down
1 change: 1 addition & 0 deletions cli/azd/cmd/testdata/TestUsage-azd-auth-status.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Global Flags
--debug : Enables debugging and diagnostics logging.
--docs : Opens the documentation for azd auth status in your web browser.
-e, --environment string : The name of the environment to use.
--fail-on-prompt : Fails with an actionable error whenever a prompt is encountered, even if a default exists. Implies --no-prompt.
-h, --help : Gets help for status.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.

Expand Down
1 change: 1 addition & 0 deletions cli/azd/cmd/testdata/TestUsage-azd-auth.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Global Flags
--debug : Enables debugging and diagnostics logging.
--docs : Opens the documentation for azd auth in your web browser.
-e, --environment string : The name of the environment to use.
--fail-on-prompt : Fails with an actionable error whenever a prompt is encountered, even if a default exists. Implies --no-prompt.
-h, --help : Gets help for auth.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.

Expand Down
1 change: 1 addition & 0 deletions cli/azd/cmd/testdata/TestUsage-azd-coding-agent.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Global Flags
--debug : Enables debugging and diagnostics logging.
--docs : Opens the documentation for azd coding-agent in your web browser.
-e, --environment string : The name of the environment to use.
--fail-on-prompt : Fails with an actionable error whenever a prompt is encountered, even if a default exists. Implies --no-prompt.
-h, --help : Gets help for coding-agent.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.

Expand Down
1 change: 1 addition & 0 deletions cli/azd/cmd/testdata/TestUsage-azd-completion-bash.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Global Flags
--debug : Enables debugging and diagnostics logging.
--docs : Opens the documentation for azd completion bash in your web browser.
-e, --environment string : The name of the environment to use.
--fail-on-prompt : Fails with an actionable error whenever a prompt is encountered, even if a default exists. Implies --no-prompt.
-h, --help : Gets help for bash.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.

Expand Down
1 change: 1 addition & 0 deletions cli/azd/cmd/testdata/TestUsage-azd-completion-fig.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Global Flags
--debug : Enables debugging and diagnostics logging.
--docs : Opens the documentation for azd completion fig in your web browser.
-e, --environment string : The name of the environment to use.
--fail-on-prompt : Fails with an actionable error whenever a prompt is encountered, even if a default exists. Implies --no-prompt.
-h, --help : Gets help for fig.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.

Expand Down
1 change: 1 addition & 0 deletions cli/azd/cmd/testdata/TestUsage-azd-completion-fish.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Global Flags
--debug : Enables debugging and diagnostics logging.
--docs : Opens the documentation for azd completion fish in your web browser.
-e, --environment string : The name of the environment to use.
--fail-on-prompt : Fails with an actionable error whenever a prompt is encountered, even if a default exists. Implies --no-prompt.
-h, --help : Gets help for fish.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Global Flags
--debug : Enables debugging and diagnostics logging.
--docs : Opens the documentation for azd completion powershell in your web browser.
-e, --environment string : The name of the environment to use.
--fail-on-prompt : Fails with an actionable error whenever a prompt is encountered, even if a default exists. Implies --no-prompt.
-h, --help : Gets help for powershell.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.

Expand Down
1 change: 1 addition & 0 deletions cli/azd/cmd/testdata/TestUsage-azd-completion-zsh.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Global Flags
--debug : Enables debugging and diagnostics logging.
--docs : Opens the documentation for azd completion zsh in your web browser.
-e, --environment string : The name of the environment to use.
--fail-on-prompt : Fails with an actionable error whenever a prompt is encountered, even if a default exists. Implies --no-prompt.
-h, --help : Gets help for zsh.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.

Expand Down
1 change: 1 addition & 0 deletions cli/azd/cmd/testdata/TestUsage-azd-completion.snap
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Global Flags
--debug : Enables debugging and diagnostics logging.
--docs : Opens the documentation for azd completion in your web browser.
-e, --environment string : The name of the environment to use.
--fail-on-prompt : Fails with an actionable error whenever a prompt is encountered, even if a default exists. Implies --no-prompt.
-h, --help : Gets help for completion.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.

Expand Down
1 change: 1 addition & 0 deletions cli/azd/cmd/testdata/TestUsage-azd-concurx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Global Flags
--debug : Enables debugging and diagnostics logging.
--docs : Opens the documentation for azd concurx in your web browser.
-e, --environment string : The name of the environment to use.
--fail-on-prompt : Fails with an actionable error whenever a prompt is encountered, even if a default exists. Implies --no-prompt.
-h, --help : Gets help for concurx.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.

Expand Down
1 change: 1 addition & 0 deletions cli/azd/cmd/testdata/TestUsage-azd-config-get.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Global Flags
--debug : Enables debugging and diagnostics logging.
--docs : Opens the documentation for azd config get in your web browser.
-e, --environment string : The name of the environment to use.
--fail-on-prompt : Fails with an actionable error whenever a prompt is encountered, even if a default exists. Implies --no-prompt.
-h, --help : Gets help for get.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Global Flags
--debug : Enables debugging and diagnostics logging.
--docs : Opens the documentation for azd config list-alpha in your web browser.
-e, --environment string : The name of the environment to use.
--fail-on-prompt : Fails with an actionable error whenever a prompt is encountered, even if a default exists. Implies --no-prompt.
-h, --help : Gets help for list-alpha.
--no-prompt : Accepts the default value instead of prompting, or it fails if there is no default.

Expand Down
Loading
Loading