-
Notifications
You must be signed in to change notification settings - Fork 362
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
Implement CLI versioning #4316
Conversation
I'm now working on actually doing something with the information, and will push more! |
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.
Rebased! |
Great work, thanks!
Also, while I agree with the clearer |
Catching up, and answering @AltGr's questions:
|
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
to2.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
beforeCmdliner.Term.eval
is invoked. Various things to note:opam adm
as an abbreviation foropam admin
so this is now implemented (seeOpamCommands.is_admin_subcommand
).OpamConsole.log
to useFormat.fprintf
instead ofPrintf.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 (sinceFormat
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 setOpamCoreConfig.!r.debug_level
before you've parsed the command-line!Sys.argv
in order to allowopam --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.--yes
to allow all commands to benefit from it. This means thatopam --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 thatopam --yes lock
now meansopam 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 seesopam 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 oropam --cli=2.0 --cl=2.1
would be a contradiction).