-
Notifications
You must be signed in to change notification settings - Fork 21
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
Switch tlapm to cmdliner #177
base: main
Are you sure you want to change the base?
Conversation
b0d1606
to
a496fa5
Compare
Unfortunately, there are no resources to change/fix the Toolbox. |
Can you expand what is meant by this? |
It means some adaptation is needed by users of tlapm. They are described in the first commit. |
I will try to fix it myself. What is the proper venue for support? Is there a mailing-list or forum? |
I've added an item to |
6fa9ff1
to
fc037ec
Compare
I don't think it is a good idea to break the public API of the command unless there's a very good reason; what do you see as the benefits of this change? |
I generally agree with this statement.
Cmdliner is a library with a nicer API than Arg that has traction in the OCaml community. It imposes POSIX and GNU conventions on command-line syntaxes and automatically generates manpages. It turns out that Cmdliner does not (and won't) support options with several arguments (as in Note that this pull request doesn't take much advantage Cmdliner's nicer API; in my opinion, more refactoring would be needed. I tried to have the changes localized in a single file for this pull request. Maybe @muenchnerkindl (the one who asked me to do this) or @damiendoligez have other reasons. |
If Stephan is interested in doing this then I am fine with it, versioning an API isn't the worst thing in the world - especially because this tool hasn't seen a point release in a while. |
Before I get too much credit for the idea, the change was suggested by @kape1395 with the objective to ultimately reduce the number of global variables. As @glondu says, the current PR is only a first step towards achieving this goal. Unfortunately, it turned out (much to our surprise) that Cmdliner doesn't support command-line options that take more than one parameter, unless separated by a symbol other than a space. |
Maybe for backwards compatibility we can:
That's not very clean from the implementation perspective, but maybe would help to resolve the problem? |
@glondu already implemented API versioning (see toolbox PR) so I don't think having a separate toolbox command would be necessary. Also not a fan of hacking around the behavior of cmdliner, which seems to go against the original reason for adopting it. |
The original reason was to reduce the number of global refs. Interpreting the I thought you were in favor of not changing the CLI API:
|
I think breaking CLI API without good reason is bad but greatly simplifying the CLI parsing code (or reducing the number of global refs, although I am not sure what that means) could be a good reason. I don't think exposing the old CLI API through an extra |
In glondu#1 I propose a small change to patch up the command line before calling Cmdliner. |
fc037ec
to
319d2a1
Compare
I've updated my branch with the tip from Damien which restores the compatibility of two-argument options. What about deprecated options? Do we want to continue to accept (and ignore) them? |
Does this make tlaplus/tlaplus#1085 obsolete? |
Oh wonderful!!! It would be nice to accept & ignore deprecated options if that does not induce any difficulty, although since the next release of TLAPM will probably be at least 1.6.0 (a minor version bump), that does indicate to users that API compatibility breaks are possible so I would accept dropping long-deprecated options. |
The part about |
So some old versions of the toolbox still send the deprecated options, which newer versions of TLAPM ignore? |
In the current state of main branches, the Toolbox sends deprecated options that TLAPM ignores. With the current state of this PR, deprecated options are removed, and TLAPM fails if they are used. So the Toolbox without tlaplus/tlaplus#1085 will still fail with the new TLAPM. |
319d2a1
to
d7b988e
Compare
I've just pushed a version that ignores deprecated options. As such, tlaplus/tlaplus#1085 is no longer required to use the new tlapm. |
Excellent! I'll take a look. Do you think tlaplus/tlaplus#1085 could be adapted to remove the unused deprecated CLI parameters? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good.
One larger change is I would like to see some in-file tests for all the CLI options. This would require a bit of git history rewriting; the CLI tests should go in their own commit, before changing to cmdliner, so we can see that they pass for the original CLI. Then the next commit is your changes to switch to using cmdliner, with the tests unchanged (or only changed by adding more tests), to see that their correctness is maintained and the cmdliner changes do not break the public API.
Arg.(value & opt int 3 & info ["wait"] ~docv:"TIME" ~doc) | ||
|
||
let stdin_t = | ||
let doc = "Read the tla file from stdin instead of file system. \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The help output spacing is weird here:
Read the tla file from stdin instead of file system. Only applies
if single tla file is provided as input.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this is due to Cmdliner justifying the text when displaying help in a terminal? "Weird" spacing disappears when using --help=plain
.
is specified, the default value is \".tlacache\"."; | ||
] | ||
is specified, the default value is \".tlacache\"." in | ||
Arg.(value & opt (some dir) None & info ["cache-dir"] ~docv:"DIR" ~doc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could make .tlacache
the default value of this parameter instead of spelling it out in the docs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this would be correct, since the command-line option overrides the environment variable TLAPM_CACHE_DIR
, and .tlacache
is used only when neither is given.
Signed-off-by: Stephane Glondu <[email protected]>
A preprocessing step strips out deprecated options (`-d`, `--paranoid`, `--isaprove`, `--fpdir`) and merges arguments of options that take two arguments (`--toolbox`, `--nofpl` and `--erasefp`). Thanks to Damien Doligez for the preprocessing idea to keep backward-compatibility. Signed-off-by: Stephane Glondu <[email protected]>
d7b988e
to
178acd7
Compare
Already done! |
|
||
(* Preprocess command line before feeding it to Cmdliner, to preserve | ||
backward compatibility. In particular, Cmdliner does not support | ||
options with direct multiple arguments. *) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add an example of the specific types of text that are being rewritten?
Thanks! Did you see the comment about testing? |
This pull request switches tlapm to cmdliner for command-line parsing. Note that it slightly changes the syntax and reverse dependencies (TLA Toolbox? VSCode?) will have to be fixed.