The unpac monorepo manager self-hosting as a monorepo using unpac
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add support for standalone completion scripts (#243)

+76 -23
+7 -4
vendor/opam/cmdliner/B0.ml
··· 65 65 let zsh = B0_env.in_scope_dir env ~/"src/tool/zsh-completion.sh" in 66 66 let ml = B0_env.in_scope_dir env ~/"src/tool/cmdliner_data.ml" in 67 67 let* bash = Os.File.read bash in 68 + let bash = String.replace_first ~sub:"_cmdliner_generic" ~by:"%s" bash in 68 69 let* zsh = Os.File.read zsh in 70 + let zsh = String.replace_first ~sub:"_cmdliner_generic" ~by:"%s" zsh in 69 71 let src = Fmt.str 70 - "let bash_generic_completion =\n{|%s\ 71 - |}\n\n\ 72 - let zsh_generic_completion =\n{|%s\ 73 - |}" bash zsh 72 + "let strf = Printf.sprintf\n\n\ 73 + let bash_generic_completion fun_name = strf\n{|%s\ 74 + |} fun_name\n\n\ 75 + let zsh_generic_completion fun_name = strf\n{|%s\ 76 + |} fun_name" bash zsh 74 77 in 75 78 Os.File.write ~force:true ~make_path:false ml src 76 79
+5
vendor/opam/cmdliner/CHANGES.md
··· 1 1 2 + - cmdliner tool: add support for generating standalone completion 3 + scripts via the `--standalone-completion`. Can be used if your 4 + users don't have the cmdliner library installed (#243). 5 + Thanks to Brian Ward for suggesting. 6 + 2 7 - Improve bash completion of long options with `=` (#231). 3 8 Thanks to Brian Ward for the patch. 4 9 - Improve bash completion on files and directories (#238).
+8 -6
vendor/opam/cmdliner/src/tool/cmdliner_data.ml
··· 1 - let bash_generic_completion = 2 - {|_cmdliner_generic() { 1 + let strf = Printf.sprintf 2 + 3 + let bash_generic_completion fun_name = strf 4 + {|%s() { 3 5 local words cword 4 6 # Equivalent of COMP_WORDS, COMP_CWORD but allow us to exclude '=' as a word separator 5 7 _get_comp_words_by_ref -n = words cword ··· 67 69 done } < <(eval $line) 68 70 return 0 69 71 } 70 - |} 72 + |} fun_name 71 73 72 - let zsh_generic_completion = 73 - {|function _cmdliner_generic { 74 + let zsh_generic_completion fun_name = strf 75 + {|function %s { 74 76 local w=("${words[@]}") # Keep words intact for restart completion 75 77 local prefix="${words[CURRENT]}" 76 78 w[CURRENT]="--__complete=${words[CURRENT]}" ··· 142 144 _describe -V unsorted completions -U 143 145 fi 144 146 } 145 - |} 147 + |} fun_name
+56 -13
vendor/opam/cmdliner/src/tool/cmdliner_main.ml
··· 253 253 val generic_script_name : string 254 254 val generic_completion : string 255 255 val tool_script_name : toolname:string -> string 256 - val tool_completion : toolname:string -> string 256 + val tool_completion : toolname:string -> standalone:bool -> string 257 257 end 258 258 259 259 type shell = (module SHELL) ··· 262 262 let name = "bash" 263 263 let sharedir = "bash-completion/completions" 264 264 let generic_script_name = "_cmdliner_generic" 265 - let generic_completion = Cmdliner_data.bash_generic_completion 265 + let generic_completion = 266 + Cmdliner_data.bash_generic_completion "_cmdliner_generic" 267 + 266 268 let tool_script_name ~toolname = toolname 267 - let tool_completion ~toolname = strf 269 + let tool_completion ~toolname ~standalone = 270 + if not standalone then 271 + strf 268 272 {|if ! declare -F _cmdliner_generic > /dev/null; then 269 273 _completion_loader _cmdliner_generic 270 274 fi 271 275 complete -F _cmdliner_generic %s 272 276 |} toolname 277 + else 278 + let munge s = String.map (function '-' -> '_' | c -> c) s in 279 + let fun_name = strf "_%s_cmdliner" (munge toolname) in 280 + let fun_def = Cmdliner_data.bash_generic_completion fun_name in 281 + strf 282 + {| 283 + %s 284 + if ! declare -F %s > /dev/null; then 285 + _completion_loader %s 286 + fi 287 + complete -F %s %s 288 + |} fun_def fun_name fun_name fun_name toolname 273 289 end 274 290 275 291 module Zsh = struct 276 292 let name = "zsh" 277 293 let sharedir = "zsh/site-functions" 278 294 let generic_script_name = "_cmdliner_generic" 279 - let generic_completion = Cmdliner_data.zsh_generic_completion 295 + let generic_completion = 296 + Cmdliner_data.zsh_generic_completion "_cmdliner_generic" 297 + 280 298 let tool_script_name ~toolname = "_" ^ toolname 281 - let tool_completion ~toolname = strf 299 + let tool_completion ~toolname ~standalone = 300 + if not standalone then 301 + strf 282 302 {|#compdef %s 283 303 autoload _cmdliner_generic 284 304 _cmdliner_generic 285 305 |} toolname 306 + else 307 + let munge s = String.map (function '-' -> '_' | c -> c) s in 308 + let fun_name = strf "_%s_cmdliner" (munge toolname) in 309 + let fun_def = Cmdliner_data.zsh_generic_completion fun_name in 310 + strf 311 + {|#compdef %s 312 + %s 313 + %s 314 + |} toolname fun_def fun_name 286 315 end 287 316 288 317 let shells : shell list = [(module Bash); (module Zsh)] ··· 292 321 print_string Shell.generic_completion; 293 322 Cmdliner.Cmd.Exit.ok 294 323 295 - let tool_completion (module Shell : SHELL) ~toolname = 324 + let tool_completion (module Shell : SHELL) ~toolname ~standalone = 296 325 with_binary_stdout @@ fun () -> 297 - print_string (Shell.tool_completion ~toolname); 326 + print_string (Shell.tool_completion ~toolname ~standalone); 298 327 Cmdliner.Cmd.Exit.ok 299 328 300 329 (* Install commands *) ··· 317 346 318 347 let install_tool_completion 319 348 ~dry_run ~update_opam_install ~shells ~toolnames ~sharedir 349 + ~standalone_completion:standalone 320 350 = 321 351 with_binary_stdout @@ fun () -> 322 352 let install ~dry_run ~toolnames sharedir acc (module Shell : SHELL) = ··· 325 355 Filename.concat Shell.sharedir (Shell.tool_script_name ~toolname) 326 356 in 327 357 let path = Filename.concat sharedir rel_path in 328 - write_file ~dry_run path (Shell.tool_completion ~toolname); 358 + write_file ~dry_run path (Shell.tool_completion ~toolname ~standalone); 329 359 (path, rel_path) :: acc 330 360 in 331 361 mkdir ~dry_run (Filename.concat sharedir Shell.sharedir); ··· 363 393 364 394 let install_tool_support 365 395 ~dry_run ~update_opam_install tools shells ~prefix ~sharedir ~mandir 396 + ~standalone_completion 366 397 = 367 398 let sharedir = match sharedir with 368 399 | None -> Filename.concat prefix "share" | Some sharedir -> sharedir ··· 375 406 let toolnames = List.map snd (List.map split_toolname tools) in 376 407 install_tool_completion 377 408 ~dry_run ~update_opam_install ~shells ~toolnames ~sharedir 409 + ~standalone_completion 378 410 379 411 (* Tool command listing command *) 380 412 ··· 391 423 let doc = "Do not install, output paths that would be written." in 392 424 Arg.(value & flag & info ["dry-run"] ~doc) 393 425 426 + let standalone_completion = 427 + let doc = "Generate standalone completion scripts. These scripts do \ 428 + not depend on the generic cmdliner completion scripts." 429 + in 430 + Arg.(value & flag & info ["standalone-completion"] ~doc) 431 + 394 432 let update_opam_install = 395 433 let doc = 396 434 "Update or create an opam $(b,.install) file $(docv) with install moves \ ··· 516 554 ] 517 555 in 518 556 Cmd.make (Cmd.info "tool-completion" ~doc ~man) @@ 519 - let+ shell = shell_pos0 and+ toolname = toolname_pos1 in 520 - tool_completion shell ~toolname 557 + let+ shell = shell_pos0 and+ toolname = toolname_pos1 558 + and+ standalone = standalone_completion in 559 + tool_completion shell ~toolname ~standalone 521 560 522 561 let install_generic_completion_cmd = 523 562 let doc = "Install generic completion scripts" in ··· 562 601 (* No let punning in < 4.13 *) 563 602 let+ dry_run = dry_run and+ shells = shells_opt 564 603 and+ update_opam_install = update_opam_install 565 - and+ toolnames = toolnames_posleft and+ sharedir = sharedir_poslast in 604 + and+ toolnames = toolnames_posleft and+ sharedir = sharedir_poslast 605 + and+ standalone_completion in 566 606 install_tool_completion 567 607 ~dry_run ~update_opam_install ~shells ~toolnames ~sharedir 608 + ~standalone_completion 568 609 569 610 let install_tool_manpages_cmd = 570 611 let doc = "Install tool and subcommand manpages" in ··· 604 645 in 605 646 Cmd.make (Cmd.info "tool-support" ~doc ~man) @@ 606 647 let+ dry_run = dry_run and+ update_opam_install = update_opam_install 607 - and+ shells = shells_opt and+ tools = tools_posleft and+ sharedir = sharedir_opt 608 - and+ mandir = mandir_opt and+ prefix = prefix in 648 + and+ shells = shells_opt and+ tools = tools_posleft 649 + and+ sharedir = sharedir_opt and+ mandir = mandir_opt and+ prefix = prefix 650 + and+ standalone_completion in 609 651 install_tool_support 610 652 ~dry_run ~update_opam_install tools shells ~prefix ~sharedir ~mandir 653 + ~standalone_completion 611 654 612 655 let install_cmd = 613 656 let doc = "Install support files for cmdliner tools" in