Custom Exit Code

I have a need to specify exit codes based on the thrown error type. It seems there might be an API for that https://github.com/apple/swift-argument-parser/pull/79.

But I am having a hard time figuring out how I am supposed to actually use this API to specify my own exit code.

Is an example available?

If you want to exit with a specific error code, the way to do that currently is to throw an ExitCode error or pass one to MyCommand.exit(with:). Neither of these will print anything, so you'd want to print any error message to stderr first.

There's an issue here for handling CustomNSErrors better, which will let you build an error with a custom description and a custom exit code: https://github.com/apple/swift-argument-parser/issues/243

1 Like

You created that issue 6 hours ago. I wrote that message yesterday before continuing to come up with a solution for the rest of the night. I swear I looked before writing the message. Clearly not before posting.

I'll see if I cannot implement that feature since it is marked as a starter.

Also, obviously coincidences and all that... but that's some crazy timing. :laughing:

Terms of Service

Privacy Policy

Cookie Policy