Document exit codes in CLI help output and return exit code 2 for input errors#1546
Conversation
…rs return non-zero exit codes Co-authored-by: waldekmastykarz <11164679+waldekmastykarz@users.noreply.github.com>
Co-authored-by: waldekmastykarz <11164679+waldekmastykarz@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
There was a problem hiding this comment.
Pull request overview
This PR improves Dev Proxy’s CLI contract by documenting exit codes in --help output and consistently distinguishing invalid input/usage from runtime failures via exit code mapping.
Changes:
- Add a help-action wrapper that appends an “Exit codes” section to CLI help output.
- Map parse/validation errors (
parseResult.Errors) to exit code2(invalid input/usage), keeping runtime errors as1.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| DevProxy/Commands/ExitCodeHelpAction.cs | Adds a HelpAction wrapper that appends the standardized exit-codes section to help output. |
| DevProxy/Commands/DevProxyCommand.cs | Wraps the help option’s action with ExitCodeHelpAction and maps parse/validation errors to exit code 2 after invocation. |
garrytrinder
left a comment
There was a problem hiding this comment.
Tested: all exit codes correct (0 for --help, 2 for validation errors). ExitCodeHelpAction properly wraps help output with exit code documentation. Code review clean — no regressions.
Validation errors (bad IP, invalid log level, etc.) were reported as returning exit code 0. Verified that with current System.CommandLine
2.0.0-beta5, all validators usinginput.AddError()already return exit code 1 correctly. The remaining gaps were that exit codes were undocumented in--help, and input validation errors were not distinguished from runtime errors.ExitCodeHelpAction: Wraps the defaultHelpActionto append an exit codes section to all help output (root + subcommands):DevProxyCommand.ConfigureCommand(): Replaces theHelpOption's action with the wrapper after all options/commands are registeredDevProxyCommand.InvokeAsync(): Maps parse/validation errors to exit code 2, distinguishing them from runtime errors (exit code 1), following conventions fromcurl,git, and othersVerified behavior:
devproxy --help→ exit code 0devproxy --ip-address "not-an-ip"→ exit code 2devproxy --bogus→ exit code 2devproxy --log-level bogus→ exit code 2devproxy --timeout abc→ exit code 2Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.