Skip to content

Update vendored cmdliner to 2.1.1 - #14636

Merged
Alizter merged 7 commits into
ocaml:mainfrom
ElectreAAS:push-ypyxsntwwwmk
May 28, 2026
Merged

Alizter merged 7 commits into
ocaml:mainfrom
ElectreAAS:push-ypyxsntwwwmk

Conversation

@ElectreAAS

@ElectreAAS ElectreAAS commented May 21, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #12515.
This PR pulls in all the changes from cmdliner 2.1.1, see changelog here.
Among these changes, there are new error messages formats, so that's a big diff on that commit.
On top of the released cmdliner, there is a singular patch to keep support for aliases.
This has the non-insignificant bonus of simplifying maintenance of our fork over at https://github.com/ocaml-dune/cmdliner

Comment thread vendor/update-cmdliner.sh Outdated
(
cd $TMP
git clone https://github.com/ocaml-dune/cmdliner.git
git clone https://github.com/ElectreAAS/dune-cmdliner.git

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Did you do (cd vendor/ && ./update-cmdliner.sh) to check that the script still works and leaves no diff?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This script will not work as-is. You need to add a second argument to git clone and name the target directory cmdliner, otherwise it will create dune-cmdliner.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I checked now, and with a simple mv it works.
The call to dune subst (which was unique in the vendor scripts) was removed as it failed with

Error: There is no dune-project file in the current directory, please add one
with a (name <name>) field in it.
Hint: 'dune subst' must be executed from the root of the project.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we keep this on https://github.com/ocaml-dune/cmdliner ? Pulling in specific contributors forks when we have a shared community source seems like unnecessary fragmentation.

| Error err -> err::errs,args
let cline = Cmdliner_def.Cline.add arg_info arg cline in
let errs, args =
match Cmdliner_def.Arg_info.alias arg_info name value with

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
match Cmdliner_def.Arg_info.alias arg_info name value with
if for_completion then errs, args
else match Cmdliner_def.Arg_info.alias arg_info name value with

We probably don't want to expand these when doing completion.

It doesn't have to be in this PR, but I thought I'd point it out anyway.

@rgrinberg

Copy link
Copy Markdown
Member

What happened to the benchmarks?

Do we have tests that show that we can still use abbreviated command names?

@Alizter

Alizter commented May 22, 2026

Copy link
Copy Markdown
Collaborator

What happened to the benchmarks?

They are having a bad day today. They will resolve themselves soon.

Do we have tests that show that we can still use abbreviated command names?

Yes, this is the main change between 2.0 and 2.1. A mechanism to support the old prefixes was added. These are all exercised in the dune init tests and a few others.

@ElectreAAS

Copy link
Copy Markdown
Collaborator Author

Do we have tests that show that we can still use abbreviated command names?

We do have some, but only by (I assume) accident:

We may have others depending on typos. If you think they'd be needed with this PR I'll add a few that specifically test for this

@Alizter

Alizter commented May 22, 2026

Copy link
Copy Markdown
Collaborator

@rgrinberg Here are the patches on the newer cmdliner that we will maintain from now on:

dbuenzli/cmdliner@master...ElectreAAS:dune-cmdliner:push-rtpovsrrqquv

in cmdliner_trie.ml at the bottom, we hardcode the legacy prefix support.

@shonfeder
shonfeder requested a review from Sudha247 May 25, 2026 12:40
@shonfeder

Copy link
Copy Markdown
Member

The dune init tests use prefixes too:

@shonfeder shonfeder left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just a few requests here for readability and clear comments.
Nice work on this change!

Comment thread test/blackbox-tests/test-cases/dune Resolved
Comment thread vendor/cmdliner/src/cmdliner_arg.ml Resolved
Comment thread vendor/cmdliner/src/cmdliner_trie.ml Resolved
(OCAML_COLOR always))
(OCAML_COLOR always)
;; Cmdliner 2.0 uses colors. With this option we have quotes like before.
(NO_COLOR 1))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If I understood correctly, cmdliner 2.x enables color by default, which means the average Dune user would see colors in all cmdliner outputs within Dune. Is this still the recommended way to disable color? In that case, should we document this in Dune docs?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Actually we have a few colour variables in dune itself. We could probably tie these together. This seems like a sensible follow up PR with a documentation effort too.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good point.
I think we don't need to expose the cmdliner-specific NO_COLOR, as it's a kind of implementation detail.
However we maybe should pick up the variable's value in our own color handling code.

Which now that I've checked, we don't have any doc on how to do this, or did I miss it?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@ElectreAAS We probably don't have any documentation in the manual, but dune build --help does mention CLICOLOR.

Signed-off-by: Ambre Austen Suhamy <[email protected]>
Signed-off-by: Ambre Austen Suhamy <[email protected]>
@ElectreAAS
ElectreAAS force-pushed the push-ypyxsntwwwmk branch from 64cc66a to 5d2efea Compare May 27, 2026 14:31
@ElectreAAS
ElectreAAS force-pushed the push-ypyxsntwwwmk branch from 5d2efea to ceebc6d Compare May 27, 2026 14:46
@ElectreAAS

Copy link
Copy Markdown
Collaborator Author

I've pushed new comments to answer reviews.
A few CI failures were due to new tests being added after the creation of this PR, but I had carelessly rebased on top of them. It should be fixed now 🤞

@Alizter

Alizter commented May 27, 2026

Copy link
Copy Markdown
Collaborator

@ElectreAAS Did you sync your fork with the new changes?

@Alizter
Alizter requested a review from shonfeder May 27, 2026 15:26

@shonfeder shonfeder left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we should keep basing this out of ocaml-dune/cmdliner, but otherwise looks fine and I wouldn't insist if others object to that suggestion.

Comment thread vendor/update-cmdliner.sh Outdated
(
cd $TMP
git clone https://github.com/ocaml-dune/cmdliner.git
git clone https://github.com/ElectreAAS/dune-cmdliner.git

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we keep this on https://github.com/ocaml-dune/cmdliner ? Pulling in specific contributors forks when we have a shared community source seems like unnecessary fragmentation.

`dune bui` as a shorthand for `dune build`. This feature was mostly deleted
in cmdliner 2.0, with a backdoor allowing these 'legacy prefixes' below.
Since we make use of these prefixes in dune, we always allow them.
See also https://github.com/ocaml/dune/issues/12515#issuecomment-3802602856

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is great, thanks!

@ElectreAAS

Copy link
Copy Markdown
Collaborator Author

I think we should keep basing this out of ocaml-dune/cmdliner, but otherwise looks fine and I wouldn't insist if others object to that suggestion.

Yep that was always the goal, the fork was put there to make sure the update script did indeed produce the same code as what's in this PR

@ElectreAAS

ElectreAAS commented May 28, 2026 •

Copy link
Copy Markdown
Collaborator Author

As this has been approved, I'll go ahead and start the merge process
It's however a bit longer than just a button click:

  • Push the necessary changes to ocaml-dune#main
  • change this PR so that vendor/update-cmdliner.sh points to the ocaml-dune fork instead of mine, and to the correct commit hash
  • make sure the update script still works as expected
  • merge this PR

@Alizter Alizter left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I've done a thorough audit of our fork and this is correctly preserving all the behaviour that we want.

Signed-off-by: Ambre Austen Suhamy <[email protected]>
@Alizter
Alizter merged commit b940d9d into ocaml:main May 28, 2026
38 of 57 checks passed
@ElectreAAS
ElectreAAS deleted the push-ypyxsntwwwmk branch May 28, 2026 15:48
@ElectreAAS ElectreAAS mentioned this pull request May 29, 2026
3 tasks done
@shonfeder shonfeder self-assigned this Jun 1, 2026
ElectreAAS added a commit that referenced this pull request Jun 25, 2026
Follow-up to #14636, which bumped the version of cmdliner to 2.1.1
This version bump allows us to use the command completion features of
cmdliner for supported shells: `bash`, `zsh`, and `powershell`.

### What is included
For supported shells
- (sub)command completion: `dune b<tab> -> dune build`
- (sub)command suggestion `dune init <tab> -> executable library ...`
- flag completion & suggestion `dune build --pro <tab> -> --profile
--promote-install-files`

### What is NOT included
- Target completion `dune build <tab> -> @test @install ...`. The code
infrastructure for this isn't present in dune yet, from what I
understand it'd be a significant undertaking.
- Completion for fish 🐟 😢 

### Experimental testing
I was only able to test that this works in bash on my machine, reviewer
help for zsh and more importantly powershell would be welcome.
To test this PR:
- For bash ([you might need this
first](https://github.com/scop/bash-completion)), either run `dune
completion bash > ~/.local/share/bash-completion/completions/dune`, or
add `eval "$(dune completion bash)"` to your bashrc
- For zsh ([you might need this
first](https://github.com/zsh-users/zsh-completions)), run `dune
completion zsh > ~/.local/share/zsh/site-functions/_dune`, and make sure
that directory is in your `$fpath`: you might need to add
`fpath+=~/.local/share/zsh/site-functions` to your .zshrc before
`compinit`.
- For powershell, either run `dune completion pwsh >>
$PROFILE.CurrentUserCurrentHost` or add `Invoke-Expression
-Command $(dune completion pwsh | Out-String)` to your profile script

You should be able to see completions!

### Thanks
All my thanks to `The cmdliner programmers` whose work made this
possible. @dbuenzli & @WardBrian ❤️

---------

Signed-off-by: Ambre Austen Suhamy <[email protected]>
@Alizter Alizter added this to the 3.25.0 milestone Jul 8, 2026
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.

Update vendored cmdliner to 2.1.1

5 participants