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

Implement CLI versioning #4316

Merged
merged 10 commits into from
Aug 26, 2020
Merged

Implement CLI versioning #4316

merged 10 commits into from
Aug 26, 2020

Conversation

dra27
Copy link
Member

@dra27 dra27 commented Aug 18, 2020

Implements the CLI Versioning spec

Fundamentally, this PR allows the user/author to select backwards-compatibility with the opam 2.0 CLI by setting OPAMCLI to 2.0 and forwards-compatibility with future releases of the opam client by passing --cli=2.1 anywhere on the command line.

This is implemented by increasing the pre-processing which is done to Sys.argv before Cmdliner.Term.eval is invoked. Various things to note:

  • While refactoring, I noticed that there's no reason for not supporting opam adm as an abbreviation for opam admin so this is now implemented (see OpamCommands.is_admin_subcommand).
  • I've converted OpamConsole.log to use Format.fprintf instead of Printf.fprintf which has been on my TODO-list for a while. This actually improves the Windows story ever-so-slightly and it turns out with only tiny alterations to a couple of messages which included @ signs. In future, it will allow the formatting to be applied using tags which will be better in terms of the code and also better for Windows (since Format will do the heavy lifting instead of my horrendous VT100 parser). I've done it here because I wanted to be able to debug the CLI parsing process, and its hard to set OpamCoreConfig.!r.debug_level before you've parsed the command-line!
  • opam already included pre-processing of Sys.argv in order to allow opam --yes plugin args to mean "automatically build and install plugin and then call it with args". I've extracted this pre-processing and included the --cli processing with it.
  • I have changed the processing of --yes to allow all commands to benefit from it. This means that opam --yes list now works, where before it was a syntax error. This is necessary to allow plugins to become built-in commands compatibly. At the moment this has a slight change of semantics in that opam --yes lock now means opam lock --yes where before the plugin would not have been invoked with --yes. I think this is acceptable and consistent to do universally, rather than tying that handling to CLI version (although we could...).
  • --yes is transformed - that is, opam --yes list is still handled by Cmdliner, it just sees opam list --yes instead. --cli is completely extracted since it affects the generation of the Cmdliner parser - --cli itself is included in the parser only so that it's included in --help (in particular, this is why parsing the prefix --cl is important or opam --cli=2.0 --cl=2.1 would be a contradiction).

@dra27 dra27 added AREA: UI PR: WIP Not for merge at this stage labels Aug 18, 2020
@dra27 dra27 added this to the 2.1.0~beta milestone Aug 18, 2020
@dra27
Copy link
Member Author

dra27 commented Aug 18, 2020

I'm now working on actually doing something with the information, and will push more!

@rjbou rjbou marked this pull request as ready for review August 21, 2020 15:47
Using Format instead of Printf tidies up the Windows version of the
logging, since writing to a buffer and a channel become equivalent.
Technically, this now permits colour in log lines! It also opens the
door for using semantic tags instead of embedded escape sequences which
will allow the code to be further simplified.

The only downside is that the @ character now needs escaping in a few
messages.
Allow OpamConsole.log to be used before OpamCoreConfig.set has been
called. debug_level defaults to 0, so any debugging messages sent to
OpamConsole.log before the config has been loaded are dropped. This PR
stores them with their timestamp and level and on the first call to
OpamConsole.log after OpamCoreConfig.set has been called, these log
lines are reinspected and printed if necessary. The only caveat is that
the log lines are always evaluated (i.e. OpamConsole.slog with `%a` has
no computational benefit).
To be used for CLI options where it's necessary for opam to know whether
the value came from the command line, the environment or is the default.
Generalises the type used for OPAMSWITCH.
@rjbou
Copy link
Collaborator

rjbou commented Aug 24, 2020

Rebased!

@AltGr
Copy link
Member

AltGr commented Aug 26, 2020

Great work, thanks!
I have a couple questions:

  • you remove the individual commands from OpamCommands; I don't mind, but did you ensure they weren't useful when calling as lib?
  • did you check the changelog to make sure OPAMCLI=2.0 works as expected on all current cli changes?

Also, while I agree with the clearer opam --yes plugin args, in this case it would seem more obvious to me that --yes only applies to opam and not to plugin. Also, it seems that opam plugin --yes no longer passes the --yes option to opam, as I believe was the case (I don't remember precisely where it was useful, but I think some scripts used it to e.g. allow format upgrade; @avsm might remember more). I am just being overly prudent about potential breakages ;)

@rjbou rjbou merged commit 4bc0fc2 into ocaml:master Aug 26, 2020
@dra27
Copy link
Member Author

dra27 commented Sep 7, 2020

Catching up, and answering @AltGr's questions:

  • I'm not sure why anyone would want to use the commands and, if they did then they need to handle CLI versioning now - so I went with "it needs to be broken, rather than silently wrong" idea!
  • Note that this PR didn't implement any of the actual changes - it's just the handling. So I have a big TODO list of the things which need addressing (I posted it in Slack before vacation). However, it's also the case that things which don't work as before are bugs, so are fixable in a 2.1 point release (obviously, we should aim to deal with them before release!)
  • I don't think opam plugin --yes ever passed the --yes option to opam before?! The scanning for the auxiliary command happened earlier than that, I think?

@dra27 dra27 mentioned this pull request Dec 3, 2020
38 tasks
@dra27 dra27 mentioned this pull request Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AREA: UI PR: WIP Not for merge at this stage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants