···6363 B0_unit.of_action "update-cmdliner-data" @@ fun env _ ~args:_ ->
6464 let bash = B0_env.in_scope_dir env ~/"src/tool/bash-completion.sh" in
6565 let zsh = B0_env.in_scope_dir env ~/"src/tool/zsh-completion.sh" in
6666+ let pwsh = B0_env.in_scope_dir env ~/"src/tool/pwsh-completion.ps1" in
6667 let ml = B0_env.in_scope_dir env ~/"src/tool/cmdliner_data.ml" in
6768 let* bash = Os.File.read bash in
6869 let bash = String.replace_first ~sub:"_cmdliner_generic" ~by:"%s" bash in
6970 let* zsh = Os.File.read zsh in
7071 let zsh = String.replace_first ~sub:"_cmdliner_generic" ~by:"%s" zsh in
7272+ let* pwsh = Os.File.read pwsh in
7373+ let pwsh = String.replace_first ~sub:"_cmdliner_generic" ~by:"%s" pwsh in
7174 let src = Fmt.str
7275 "let strf = Printf.sprintf\n\n\
7373- let bash_generic_completion fun_name = strf\n{|%s\
7676+ let bash_generic_completion fun_name = strf \n{|%s\
7777+ |} fun_name\n\n\
7878+ let zsh_generic_completion fun_name = strf \n{|%s\
7479 |} fun_name\n\n\
7575- let zsh_generic_completion fun_name = strf\n{|%s\
7676- |} fun_name" bash zsh
8080+ let pwsh_generic_completion fun_name = strf \n{|%s\
8181+ |} fun_name" bash zsh pwsh
7782 in
7883 Os.File.write ~force:true ~make_path:false ml src
7984
+3
vendor/opam/cmdliner/CHANGES.md
···11+22+- completion: add support for powershell (#214)
33+ Thanks to Brian Ward for the work.
1425- cmdliner tool: add support for generating standalone completion
36 scripts via the `--standalone-completion`. Can be used if your
+5-4
vendor/opam/cmdliner/DEVEL.md
···15151616 source ./src/tool/zsh-completion.sh # zsh
1717 source ./src/tool/bash-completion.sh # bash
1818-1919-This replaces the generic completion function used by tool completion
1818+ . ./src/tool/pwsh-completion.ps1 # powershell
1919+2020+This replaces the generic completion function used by tool completion
2021scripts with the new definition. Trying to complete tools should now
2121-use the new definitions. To test the file, directory and path completions
2222-you can also use this test (invoke with `--help`)
2222+use the new definitions. To test the file, directory and path
2323+completions you can also use this test (invoke with `--help`)
23242425 b0 -- test_shell
2526
+37-3
vendor/opam/cmdliner/doc/cli.mld
···183183184184The completion process happens via a {{!completion_protocol}protocol}
185185which is interpreted by generic shell completion scripts that are
186186-installed by the library. For now the [zsh] and [bash] shells are
187187-supported.
186186+installed by the library. For now the [zsh], [bash], and PowerShell
187187+([pwsh]) shells are supported.
188188189189Tool developers can easily {{!install_tool_completion}install}
190190completion definitions that invoke these completion scripts. Tool
···295295are on [< 2.12] and in [2.12] [_completion_loader] simply calls
296296[_comp_load].
297297298298+{3:user_pwsh For PowerShell ([pwsh])}
299299+300300+PowerShell Core supports tab completion but lacks the kind of
301301+discovery mechanism that other shells have for these scripts.
302302+303303+Therefore, you need to explicitly source the completion script
304304+for cmdliner based tools. This can be done in the
305305+{{:https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles} [$profile]}
306306+file by adding something like the following:
307307+308308+{@ps1[
309309+# first, load the generic cmdliner completion function
310310+. "$(opam var share)/powershell/cmdliner-generic.ps1"
311311+# then, register each tool you want completions for
312312+# for example:
313313+. "$(opam var share)/powershell/cmdliner_completion.ps1"
314314+. "$(opam var share)/powershell/odoc_completion.ps1"
315315+# ...
316316+]}
317317+318318+Note that these instruction do not react dynamically to [opam]
319319+switches changes so you may see odd completion behaviours when you do
320320+so, see this {{:https://github.com/ocaml/opam/issues/6427}this opam
321321+issue}.
322322+323323+With this setup, if you are using a cmdliner based tool named
324324+[thetool] that did not {{!install_tool_completion}install} a completion
325325+definition. You can always do it yourself by invoking:
326326+327327+{@ps1[
328328+Register-ArgumentCompleter -Native -CommandName thetool -ScriptBlock $Global:_cmdliner_generic
329329+]}
330330+298331{2:install_completion Install}
299332300333Completion scripts need to be installed in subdirectories of a
···310343311344{ul
312345{- For [zsh] it is [$SHAREDIR/zsh/site-functions]}
313313-{- For [bash] it is [$SHAREDIR/bash-completion/completions]}}
346346+{- For [bash] it is [$SHAREDIR/bash-completion/completions]}
347347+{- For [pwsh] it is [$SHAREDIR/powershell]}}
314348315349If that is unsatisfying you can output the completion scripts directly
316350where you want with the [cmdliner generic-completion] and