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

Switch tlapm to cmdliner #177

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

glondu
Copy link

@glondu glondu commented Nov 21, 2024

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.

@lemmy
Copy link
Member

lemmy commented Nov 21, 2024

Unfortunately, there are no resources to change/fix the Toolbox.

@lemmy lemmy added the enhancement A new feature, an improvement, or other addition. label Nov 21, 2024
@ahelwer
Copy link
Collaborator

ahelwer commented Nov 21, 2024

Note that it slightly changes the syntax and reverse dependencies (TLA Toolbox? VSCode?) will have to be fixed.

Can you expand what is meant by this?

@glondu
Copy link
Author

glondu commented Nov 22, 2024

Note that it slightly changes the syntax and reverse dependencies (TLA Toolbox? VSCode?) will have to be fixed.

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.

@glondu
Copy link
Author

glondu commented Nov 22, 2024

Unfortunately, there are no resources to change/fix the Toolbox.

I will try to fix it myself. What is the proper venue for support? Is there a mailing-list or forum?

@glondu
Copy link
Author

glondu commented Nov 22, 2024

Unfortunately, there are no resources to change/fix the Toolbox.

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 tlapm --config output and adapted the Toolbox in tlaplus/tlaplus#1085

@ahelwer
Copy link
Collaborator

ahelwer commented Nov 22, 2024

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?

@glondu
Copy link
Author

glondu commented Nov 25, 2024

I don't think it is a good idea to break the public API of the command unless there's a very good reason

I generally agree with this statement.

what do you see as the benefits of this change?

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 --toolbox A B) because it doesn't fit said conventions. I chose to support --toolbox A,B which is Cmdliner's default for this kind of option. Note that --toolbox=A,B is also automatically supported. I could have chosen --toolbox "A B" as well (but it doesn't solve the compatibility issue).

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.

@ahelwer
Copy link
Collaborator

ahelwer commented Nov 26, 2024

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.

@muenchnerkindl
Copy link
Contributor

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.

@kape1395
Copy link
Collaborator

Maybe for backwards compatibility we can:

  • support --toolbox A:B or a variant of that with some delimiters. ":" seems natural to specify a range.
  • If --toolbox A B is provided, consider --toolbox A as a "named option" and "B" as a separate "positional" argument.
    I guess currently, all the positional options are considered files. But if --toolbox only gets one number and there is a positional argument that looks like a number, consider it an end of the range.

That's not very clean from the implementation perspective, but maybe would help to resolve the problem?

@ahelwer
Copy link
Collaborator

ahelwer commented Nov 26, 2024

@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.

@kape1395
Copy link
Collaborator

The original reason was to reduce the number of global refs. Interpreting the cmdliner arguments doesn't sound like hacking it or objecting to the initial goal.

I thought you were in favor of not changing the CLI API:

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?

@ahelwer
Copy link
Collaborator

ahelwer commented Nov 26, 2024

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 --toolbox flag is a good design; it's easy to update the toolbox to use the new API, the hard part is dealing with people using the old toolbox before those fixes and new version of TLAPM. (edit: I misunderstood, the --toolbox flag is the actual CLI arg that is broken not a new arg we are adding for compatibility).

@damiendoligez
Copy link
Contributor

In glondu#1 I propose a small change to patch up the command line before calling Cmdliner.

@glondu
Copy link
Author

glondu commented Dec 3, 2024

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?

@lemmy
Copy link
Member

lemmy commented Dec 3, 2024

I've updated my branch with the tip from Damien which restores the compatibility of two-argument options.

Does this make tlaplus/tlaplus#1085 obsolete?

@ahelwer
Copy link
Collaborator

ahelwer commented Dec 3, 2024

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.

@glondu
Copy link
Author

glondu commented Dec 3, 2024

I've updated my branch with the tip from Damien which restores the compatibility of two-argument options.

Does this make tlaplus/tlaplus#1085 obsolete?

The part about --toolbox, yes, but not the part about stopping using deprecated options...

@ahelwer
Copy link
Collaborator

ahelwer commented Dec 3, 2024

So some old versions of the toolbox still send the deprecated options, which newer versions of TLAPM ignore?

@glondu
Copy link
Author

glondu commented Dec 4, 2024

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.

@glondu
Copy link
Author

glondu commented Dec 4, 2024

I've just pushed a version that ignores deprecated options. As such, tlaplus/tlaplus#1085 is no longer required to use the new tlapm.

@ahelwer
Copy link
Collaborator

ahelwer commented Dec 4, 2024

Excellent! I'll take a look. Do you think tlaplus/tlaplus#1085 could be adapted to remove the unused deprecated CLI parameters?

Copy link
Collaborator

@ahelwer ahelwer left a 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.

src/tlapm_args.ml Outdated Show resolved Hide resolved
src/tlapm_args.ml Outdated Show resolved Hide resolved
src/tlapm_args.ml Show resolved Hide resolved
src/tlapm_args.ml Outdated Show resolved Hide resolved
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. \
Copy link
Collaborator

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.

Copy link
Author

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.

src/tlapm_args.ml Outdated Show resolved Hide resolved
src/tlapm_args.ml Show resolved Hide resolved
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)
Copy link
Collaborator

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?

Copy link
Author

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.

src/tlapm_args.ml Show resolved Hide resolved
Stephane Glondu added 2 commits December 11, 2024 09:49
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]>
@glondu
Copy link
Author

glondu commented Dec 11, 2024

Excellent! I'll take a look. Do you think tlaplus/tlaplus#1085 could be adapted to remove the unused deprecated CLI parameters?

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. *)
Copy link
Collaborator

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?

@ahelwer
Copy link
Collaborator

ahelwer commented Dec 11, 2024

Thanks! Did you see the comment about testing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A new feature, an improvement, or other addition.
Development

Successfully merging this pull request may close these issues.

6 participants