Skip to content

Update argument definitions with cmdliner completion functions - #6868

Open
WardBrian wants to merge 10 commits into
ocaml:masterfrom
WardBrian:cmdliner-completion
Open

Update argument definitions with cmdliner completion functions#6868
WardBrian wants to merge 10 commits into
ocaml:masterfrom
WardBrian:cmdliner-completion

Conversation

@WardBrian

Copy link
Copy Markdown
Contributor

This is patch 3/4 in a sequence for improving the opam completion and adding powershell support.

Previous: #6854 updates the opam source for compatibility with cmdliner 2.1.0, #6867 actually updates the vendored cmdliner

This PR: Updates the arg definitions in opamClient to provide completion functions for all of opam's custom argument types.

This patch breaks down into three pieces:

  • Mostly "trivial" completers like for opamlist_columns that just return a list of options
  • Switch-dependent completions for packages etc. These required utilizing the contextual piece of cmdliner's completion system, mostly wrapped in the function package_completion
  • Some (regrettably a little complicated) functionality for mk_subcommands/mk_subcommands_with_default that allows for completion of both subcommand names and the arguments for them.

The completions provided by this PR are more complete and correct than those in the current completion script.
They can be tested with

dune exec -- src/core/cmdliner/tool/opamCmdliner_tool.exe tool-completion \
  --standalone-completion bash opam > complete.sh
source ./complete.sh
Comparison

$ # current completion script
$ opam repostitory <TAB>
           add        --help     list       Note:      priority   remove     set-repos  set-url 
$ # note that the "Note:" above does really get suggested!

$ # new completion script
$ ./opam repository <TAB>
                       --confirm-level        --help                 --no-aspcud            --rank                 set-repos              --use-internal-solver  --yes
-a                     --criteria             --ignore-pin-depends   --no-auto-upgrade      --readonly             set-url                -v                     
add                    --cudf                 --json                 --no-self-upgrade      remove                 --short                --verbose              
--all-switches         --debug                -k                     --on-switches          --root                 --solver               --version              
--best-effort          --debug-level          --kind                 priority               -s                     --strict               -w                     
--cli                  --dont-select          list                   -q                     --safe                 --switch               --working-dir          
--color                --git-version          --no                   --quiet                --set-default          --this-switch          -y    

Up next: Final PR updating the build system to replace existing completion scripts and add powershell completions.

@WardBrian
WardBrian force-pushed the cmdliner-completion branch from 3d342b1 to 7965497 Compare July 23, 2026 20:50
@WardBrian
WardBrian force-pushed the cmdliner-completion branch from 7965497 to 0956610 Compare July 24, 2026 13:39
@WardBrian
WardBrian force-pushed the cmdliner-completion branch from 0956610 to 2eed079 Compare July 24, 2026 14:01
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.

1 participant