Exit with appropriate exit code when providing version by GDWR · Pull Request #1161 · microsoft/sbom-tool (original) (raw)

This Pull Request updates the handling of the --version & version subcommand to exit immediately with a 0 (successful) exit code, in scenarios that the version is correctly output. 1 (failure) will still be emitted when the version cannot be retrieved correctly.

I've noticed this while outputting debug information in pipelines, as it causes the task to fail. I can always ignore the unsuccessful exit || true etc, but I think outputting the correct exit code would be ideal.


I did have a look at utilising the "Args" return to carry the exit code back to Program.cs for handling the exiting of the application in unified manner, but it feels like a misuse of "Args" as they're intended to be client driven. If this approach is desired, from the structure of the application I would suggest moving the handling of version into a VersionService to unify how the handling of commands and subsequent exit codes are across the application. As the version logic is already different to the rest in where it is handled, I did not think this refactor would be desired. I am happy to refactor into a service if that feels more appropriate.