Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to customize the exit code #110

Open
SirNickolas opened this issue Nov 18, 2023 · 1 comment
Open

Allow to customize the exit code #110

SirNickolas opened this issue Nov 18, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@SirNickolas
Copy link
Contributor

Currently, if a parsing error occurs, the program exits with code 1; this is hard-coded into the library. However, the program may want to use return code 1 itself and leave another code for the CLI framework. If I understood correctly, to do this, we have to invoke the lower-level parseArgs manually, check if it returned 1, and if so, distinguish it from the program’s 1 somehow (e.g., by checking a global variable). It feels really hacky for such simple task.

A blog post explaining why having different error codes is important.

@andrey-zherikov
Copy link
Owner

CLI!(config, COMMAND).main!newMain is very simple - it does only this:

int main(string[] argv)
{
    return CLI!(config, COMMAND).parseArgs!(newMain)(argv[1..$]);
}

So what you can do to exit with your custom code is this:

int main(string[] argv)
{
    return CLI!(config, COMMAND).parseArgs!(newMain)(argv[1..$]) ? 123 : 0;    // exit with 123 in case of error
}

@andrey-zherikov andrey-zherikov added the enhancement New feature or request label Jan 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants