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 not exiting on error, and parse command line from the first argument #84

Merged
merged 4 commits into from
Feb 9, 2020
Merged

Conversation

aantron
Copy link
Collaborator

@aantron aantron commented Sep 5, 2019

Fixes #83.

  • Passes ~current:(ref 0) to Arg.parse_argv, to ensure ~argv is parsed from the beginning each time, in case OMP is linked into a larger process that calls into OMP multiple times.
  • Adds ?exit_on_error to functions that might parse arguments (i.e., act as top-level functions of the driver). The default value is ~exit_on_error:true, which roughly mimics the behavior before this PR. If ~exit_on_error:false is provided, none of the functions ever call exit. Instead, they raise (leak) the exceptions that would have terminated the process. I decided to add this to all functions because there are three top-level "entry points" into Driver, and they call each other, so they all need this change. It is modeled after Alcotest.run.

This changes the result type of Driver.run_main and Driver.run_as_ppx_rewriter from 'a to unit, because these functions no longer call exit in all paths unconditionally.

The exit behavior is also changed in a few other ways, even with ~exit_on_error:true:

  1. run_main no longer calls exit 0 at its ends, so execution continues in the caller.
  2. Exit codes are more disciplined. Previously, the exit code was sometimes 1 on Arg.Help, and 1 on Arg.Bad. In the former case, the help message would be printed to STDERR. Now, Arg.Help always prints to STDOUT, and the exit code is 0, and the exit code for Arg.Bad is always 2. This is in accordance with convention and this code in Arg.

Also start parsing arguments from position zero, even if the parser has
already run in this process.
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good to me

@aantron aantron merged commit 0d28ffb into ocaml-ppx:master Feb 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix parse_argv usage
1 participant