From f905e979278de33fcaf6b7d080c025b9bcde44ee Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 25 Feb 2026 12:02:54 +0000 Subject: [PATCH 1/3] Initial plan From 7cc8e2409e26bd1c01edbe9f6fcdb2b4d608e6a4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 25 Feb 2026 12:11:39 +0000 Subject: [PATCH 2/3] Add exit code documentation to help output and ensure validation errors return non-zero exit codes Co-authored-by: waldekmastykarz <11164679+waldekmastykarz@users.noreply.github.com> --- DevProxy/Commands/DevProxyCommand.cs | 7 ++++++ DevProxy/Commands/ExitCodeHelpAction.cs | 33 +++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 DevProxy/Commands/ExitCodeHelpAction.cs diff --git a/DevProxy/Commands/DevProxyCommand.cs b/DevProxy/Commands/DevProxyCommand.cs index c5c4b8b3..d66ba164 100644 --- a/DevProxy/Commands/DevProxyCommand.cs +++ b/DevProxy/Commands/DevProxyCommand.cs @@ -2,6 +2,7 @@ using DevProxy.Abstractions.Proxy; using DevProxy.Abstractions.Utils; using System.CommandLine; +using System.CommandLine.Help; using System.CommandLine.Parsing; using System.Globalization; @@ -453,6 +454,12 @@ private void ConfigureCommand() commands.AddRange(_plugins.SelectMany(p => p.GetCommands())); this.AddCommands(commands.OrderByName()); + var helpOption = Options.OfType().FirstOrDefault(); + if (helpOption?.Action is HelpAction helpAction) + { + helpOption.Action = new ExitCodeHelpAction(helpAction); + } + SetAction(InvokeAsync); } diff --git a/DevProxy/Commands/ExitCodeHelpAction.cs b/DevProxy/Commands/ExitCodeHelpAction.cs new file mode 100644 index 00000000..343cc5f1 --- /dev/null +++ b/DevProxy/Commands/ExitCodeHelpAction.cs @@ -0,0 +1,33 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.CommandLine; +using System.CommandLine.Help; +using System.CommandLine.Invocation; + +namespace DevProxy.Commands; + +sealed class ExitCodeHelpAction : SynchronousCommandLineAction +{ + private readonly HelpAction _originalAction; + + public ExitCodeHelpAction(HelpAction originalAction) + { + _originalAction = originalAction; + Terminating = true; + } + + public override int Invoke(ParseResult parseResult) + { + var result = _originalAction.Invoke(parseResult); + + var output = parseResult.Configuration.Output; + output.WriteLine(); + output.WriteLine("Exit codes:"); + output.WriteLine(" 0 Success"); + output.WriteLine(" 1 Error"); + + return result; + } +} From 1fb5fa1af162d6260b15ef6a0823186014d2a1fa Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 25 Feb 2026 13:08:42 +0000 Subject: [PATCH 3/3] Return exit code 2 for input validation and parse errors Co-authored-by: waldekmastykarz <11164679+waldekmastykarz@users.noreply.github.com> --- DevProxy/Commands/DevProxyCommand.cs | 12 +++++++++++- DevProxy/Commands/ExitCodeHelpAction.cs | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/DevProxy/Commands/DevProxyCommand.cs b/DevProxy/Commands/DevProxyCommand.cs index d66ba164..d90ea847 100644 --- a/DevProxy/Commands/DevProxyCommand.cs +++ b/DevProxy/Commands/DevProxyCommand.cs @@ -166,7 +166,17 @@ public async Task InvokeAsync(string[] args, WebApplication app) var parseResult = IsStdioCommand ? StdioCommand.ParseStdioArgs(this, args) : Parse(args); - return await parseResult.InvokeAsync(app.Lifetime.ApplicationStopping); + var exitCode = await parseResult.InvokeAsync(app.Lifetime.ApplicationStopping); + + // Return exit code 2 for input validation and parse errors to distinguish + // them from runtime errors (exit code 1), following conventions from + // curl, git, and others + if (exitCode != 0 && parseResult.Errors.Count > 0) + { + return 2; + } + + return exitCode; } private async Task InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken) diff --git a/DevProxy/Commands/ExitCodeHelpAction.cs b/DevProxy/Commands/ExitCodeHelpAction.cs index 343cc5f1..fae60aba 100644 --- a/DevProxy/Commands/ExitCodeHelpAction.cs +++ b/DevProxy/Commands/ExitCodeHelpAction.cs @@ -26,7 +26,8 @@ public override int Invoke(ParseResult parseResult) output.WriteLine(); output.WriteLine("Exit codes:"); output.WriteLine(" 0 Success"); - output.WriteLine(" 1 Error"); + output.WriteLine(" 1 Runtime error"); + output.WriteLine(" 2 Invalid input or usage"); return result; }