Skip to content

Commit f87d2ac

Browse files
committed
Upgrade cmdliner fork to 1.1.1
We still need a fork to support `alias` but this brings the upstream part to 1.1.1. The main addition is builtin support of groups through the `Cmdliner.Cmd` API. Benefits include: - we get closer to upstream `cmdliner` - help pages like `dune ocaml --help` are now more useful This commit contains several things: - an update of the vendored copy, - a port of `bin/` to the `Cmdliner.Cmd` API, - test updates, mostly typographic. Signed-off-by: Etienne Millon <me@emillon.org>
1 parent 11a8a4f commit f87d2ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+2257
-2374
lines changed

CHANGES.md

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
- Add `%{coq:...}` macro for accessing data about the configuration about Coq.
5959
For instance `%{coq:version}` (#6049, @Alizter)
6060

61+
- update vendored copy of cmdliner to 1.1.1. This improves the built-in
62+
documentation for command groups such as `dune ocaml`. (#6038, @emillon)
63+
6164
3.4.1 (26-07-2022)
6265
------------------
6366

bin/build_cmd.ml

+19-17
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ let run_build_command ~(common : Common.t) ~config ~request =
115115
| No -> run_build_command_once)
116116
~common ~config ~request
117117

118-
let runtest =
118+
let runtest_info =
119119
let doc = "Run tests." in
120120
let man =
121121
[ `S "DESCRIPTION"
@@ -131,22 +131,24 @@ let runtest =
131131
]
132132
]
133133
in
134+
Cmd.info "runtest" ~doc ~man
135+
136+
let runtest_term =
134137
let name_ = Arg.info [] ~docv:"DIR" in
135-
let term =
136-
let+ common = Common.term
137-
and+ dirs = Arg.(value & pos_all string [ "." ] name_) in
138-
let config = Common.init common in
139-
let request (setup : Import.Main.build_system) =
140-
Action_builder.all_unit
141-
(List.map dirs ~f:(fun dir ->
142-
let dir = Path.(relative root) (Common.prefix_target common dir) in
143-
Alias.in_dir ~name:Dune_engine.Alias.Name.runtest ~recursive:true
144-
~contexts:setup.contexts dir
145-
|> Alias.request))
146-
in
147-
run_build_command ~common ~config ~request
138+
let+ common = Common.term
139+
and+ dirs = Arg.(value & pos_all string [ "." ] name_) in
140+
let config = Common.init common in
141+
let request (setup : Import.Main.build_system) =
142+
Action_builder.all_unit
143+
(List.map dirs ~f:(fun dir ->
144+
let dir = Path.(relative root) (Common.prefix_target common dir) in
145+
Alias.in_dir ~name:Dune_engine.Alias.Name.runtest ~recursive:true
146+
~contexts:setup.contexts dir
147+
|> Alias.request))
148148
in
149-
(term, Term.info "runtest" ~doc ~man)
149+
run_build_command ~common ~config ~request
150+
151+
let runtest = Cmd.v runtest_info runtest_term
150152

151153
let build =
152154
let doc =
@@ -182,7 +184,7 @@ let build =
182184
in
183185
run_build_command ~common ~config ~request
184186
in
185-
(term, Term.info "build" ~doc ~man)
187+
Cmd.v (Cmd.info "build" ~doc ~man) term
186188

187189
let fmt =
188190
let doc = "Format source code." in
@@ -207,4 +209,4 @@ let fmt =
207209
in
208210
run_build_command ~common ~config ~request
209211
in
210-
(term, Term.info "fmt" ~doc ~man)
212+
Cmd.v (Cmd.info "fmt" ~doc ~man) term

bin/build_cmd.mli

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
open Dune_engine
1+
open Import
22

33
val run_build_command :
44
common:Common.t
55
-> config:Dune_config.t
6-
-> request:(Dune_rules.Main.build_system -> unit Action_builder.t)
6+
-> request:(Main.build_system -> unit Action_builder.t)
77
-> unit
88

9-
val runtest : unit Cmdliner.Term.t * Cmdliner.Term.info
9+
val runtest : unit Cmd.t
1010

11-
val build : unit Cmdliner.Term.t * Cmdliner.Term.info
11+
val runtest_term : unit Term.t
1212

13-
val fmt : unit Cmdliner.Term.t * Cmdliner.Term.info
13+
val build : unit Cmd.t
14+
15+
val fmt : unit Cmd.t

bin/cache.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ let man =
1818

1919
let doc = "Manage the shared cache of build artifacts"
2020

21-
let info = Term.info name ~doc ~man
21+
let info = Cmd.info name ~doc ~man
2222

2323
let trim ~trimmed_size ~size =
2424
Log.init_disabled ();
@@ -87,4 +87,4 @@ let term =
8787
| Some Start_deprecated | Some Stop_deprecated -> deprecated_error ()
8888
| None -> `Help (`Pager, Some name)
8989

90-
let command = (term, info)
90+
let command = Cmd.v info term

bin/cache.mli

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
val command : unit Cmdliner.Term.t * Cmdliner.Term.info
1+
open Import
2+
3+
val command : unit Cmd.t

bin/clean.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ let command =
2222
|> Path.Set.iter ~f:Path.unlink_no_err;
2323
Path.rm_rf Path.build_dir
2424
in
25-
(term, Term.info "clean" ~doc ~man)
25+
Cmd.v (Cmd.info "clean" ~doc ~man) term

bin/clean.mli

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
val command : unit Cmdliner.Term.t * Cmdliner.Term.info
1+
open Import
2+
3+
val command : unit Cmd.t

bin/common.ml

+12-11
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module Clflags = Dune_engine.Clflags
66
module Graph = Dune_graph.Graph
77
module Package = Dune_engine.Package
88
module Profile = Dune_rules.Profile
9+
module Cmd = Cmdliner.Cmd
910
module Term = Cmdliner.Term
1011
module Manpage = Cmdliner.Manpage
1112
module Only_packages = Dune_rules.Only_packages
@@ -506,7 +507,7 @@ module Options_implied_by_dash_p = struct
506507
last
507508
& opt_all (some profile) [ None ]
508509
& info [ "profile" ] ~docs
509-
~env:(Arg.env_var ~doc "DUNE_PROFILE")
510+
~env:(Cmd.Env.info ~doc "DUNE_PROFILE")
510511
~doc:
511512
(Printf.sprintf
512513
"Select the build profile, for instance $(b,dev) or \
@@ -561,7 +562,7 @@ let shared_with_config_file =
561562
& opt (some (enum all)) None
562563
& info [ "sandbox" ]
563564
~env:
564-
(Arg.env_var
565+
(Cmd.Env.info
565566
~doc:"Sandboxing mode to use by default. (see --sandbox)"
566567
"DUNE_SANDBOX")
567568
~doc:
@@ -597,7 +598,7 @@ let shared_with_config_file =
597598
Arg.(
598599
value
599600
& opt (some (enum Dune_config.Cache.Enabled.all)) None
600-
& info [ "cache" ] ~docs ~env:(Arg.env_var ~doc "DUNE_CACHE") ~doc)
601+
& info [ "cache" ] ~docs ~env:(Cmd.Env.info ~doc "DUNE_CACHE") ~doc)
601602
and+ cache_storage_mode =
602603
let doc =
603604
Printf.sprintf "Dune cache storage mode (%s). Default is `%s'."
@@ -609,7 +610,7 @@ let shared_with_config_file =
609610
value
610611
& opt (some (enum Dune_config.Cache.Storage_mode.all)) None
611612
& info [ "cache-storage-mode" ] ~docs
612-
~env:(Arg.env_var ~doc "DUNE_CACHE_STORAGE_MODE")
613+
~env:(Cmd.Env.info ~doc "DUNE_CACHE_STORAGE_MODE")
613614
~doc)
614615
and+ cache_check_probability =
615616
let doc =
@@ -625,7 +626,7 @@ let shared_with_config_file =
625626
& info
626627
[ "cache-check-probability" ]
627628
~docs
628-
~env:(Arg.env_var ~doc "DUNE_CACHE_CHECK_PROBABILITY")
629+
~env:(Cmd.Env.info ~doc "DUNE_CACHE_CHECK_PROBABILITY")
629630
~doc)
630631
and+ action_stdout_on_success =
631632
Arg.(
@@ -790,7 +791,7 @@ let term ~default_root_is_cwd =
790791
value
791792
& opt (some path) None
792793
& info [ "workspace" ] ~docs ~docv:"FILE" ~doc
793-
~env:(Arg.env_var ~doc "DUNE_WORKSPACE"))
794+
~env:(Cmd.Env.info ~doc "DUNE_WORKSPACE"))
794795
and+ promote =
795796
one_of
796797
(let+ auto =
@@ -804,7 +805,7 @@ let term ~default_root_is_cwd =
804805
Option.some_if auto Clflags.Promote.Automatically)
805806
(let+ disable =
806807
let doc = "Disable all promotion rules" in
807-
let env = Arg.env_var ~doc "DUNE_DISABLE_PROMOTION" in
808+
let env = Cmd.Env.info ~doc "DUNE_DISABLE_PROMOTION" in
808809
Arg.(value & flag & info [ "disable-promotion" ] ~docs ~env ~doc)
809810
in
810811
Option.some_if disable Clflags.Promote.Never)
@@ -892,7 +893,7 @@ let term ~default_root_is_cwd =
892893
value
893894
& opt (some string) None
894895
& info [ "build-dir" ] ~docs ~docv:"FILE"
895-
~env:(Arg.env_var ~doc "DUNE_BUILD_DIR")
896+
~env:(Cmd.Env.info ~doc "DUNE_BUILD_DIR")
896897
~doc)
897898
and+ diff_command =
898899
let doc =
@@ -903,7 +904,7 @@ let term ~default_root_is_cwd =
903904
value
904905
& opt (some string) None
905906
& info [ "diff-command" ] ~docs
906-
~env:(Arg.env_var ~doc "DUNE_DIFF_COMMAND")
907+
~env:(Cmd.Env.info ~doc "DUNE_DIFF_COMMAND")
907908
~doc)
908909
and+ stats_trace_file =
909910
Arg.(
@@ -925,7 +926,7 @@ let term ~default_root_is_cwd =
925926
& info
926927
[ "store-orig-source-dir" ]
927928
~docs
928-
~env:(Arg.env_var ~doc "DUNE_STORE_ORIG_SOURCE_DIR")
929+
~env:(Cmd.Env.info ~doc "DUNE_STORE_ORIG_SOURCE_DIR")
929930
~doc)
930931
and+ () = build_info
931932
and+ instrument_with =
@@ -938,7 +939,7 @@ let term ~default_root_is_cwd =
938939
value
939940
& opt (some (list lib_name)) None
940941
& info [ "instrument-with" ] ~docs
941-
~env:(Arg.env_var ~doc "DUNE_INSTRUMENT_WITH")
942+
~env:(Cmd.Env.info ~doc "DUNE_INSTRUMENT_WITH")
942943
~docv:"BACKENDS" ~doc)
943944
and+ file_watcher =
944945
let doc =

bin/coq.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ let sub_commands_synopsis = Common.command_synopsis [ "coq top FILE -- ARGS" ]
66

77
let man = [ `Blocks sub_commands_synopsis ]
88

9-
let info = Term.info ~doc ~man "coq"
9+
let info = Cmd.info ~doc ~man "coq"
1010

11-
let group = (Term.Group.Group [ in_group Coqtop.command ], info)
11+
let group = Cmd.group info [ Coqtop.command ]

bin/coq.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
open Import
22

3-
val group : unit Term.Group.t
3+
val group : unit Cmd.t

bin/coqtop.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let man =
1515
; `Blocks Common.help_secs
1616
]
1717

18-
let info = Term.info "top" ~doc ~man
18+
let info = Cmd.info "top" ~doc ~man
1919

2020
let term =
2121
let+ common = Common.term
@@ -137,4 +137,4 @@ let term =
137137
in
138138
restore_cwd_and_execve common coqtop argv env
139139

140-
let command = (term, info)
140+
let command = Cmd.v info term

bin/coqtop.mli

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
val command : unit Cmdliner.Term.t * Cmdliner.Term.info
1+
open Import
2+
3+
val command : unit Cmd.t

bin/describe.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ let man =
2626
; `Blocks Common.help_secs
2727
]
2828

29-
let info = Term.info "describe" ~doc ~man
29+
let info = Cmd.info "describe" ~doc ~man
3030

3131
(** whether to sanitize absolute paths of workspace items, and their UIDs, to
3232
ensure reproducible tests *)
@@ -869,4 +869,4 @@ let term : unit Term.t =
869869
| Csexp -> Csexp.to_channel stdout (Sexp.of_dyn res)
870870
| Sexp -> print_as_sexp res))
871871

872-
let command : unit Term.t * Term.info = (term, info)
872+
let command = Cmd.v info term

bin/describe.mli

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
val command : unit Cmdliner.Term.t * Cmdliner.Term.info
1+
open Import
2+
3+
val command : unit Cmd.t

bin/diagnostics.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ let exec () =
5252

5353
let info =
5454
let doc = "fetch and return errors from the current build" in
55-
Term.info "diagnostics" ~doc
55+
Cmd.info "diagnostics" ~doc
5656

5757
let term =
5858
let+ (common : Common.t) = Common.term in
5959
Rpc.client_term common exec
6060

61-
let command = (term, info)
61+
let command = Cmd.v info term

bin/diagnostics.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
open Import
22

3-
val command : unit Term.t * Term.info
3+
val command : unit Cmd.t

bin/exec.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ let man =
3030
]
3131
]
3232

33-
let info = Term.info "exec" ~doc ~man
33+
let info = Cmd.info "exec" ~doc ~man
3434

3535
let term =
3636
let+ common = Common.term
@@ -132,4 +132,4 @@ let term =
132132
in
133133
restore_cwd_and_execve common prog argv env
134134

135-
let command = (term, info)
135+
let command = Cmd.v info term

bin/exec.mli

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
val command : unit Cmdliner.Term.t * Cmdliner.Term.info
1+
open Import
2+
3+
val command : unit Cmd.t

bin/external_lib_deps.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let man =
1414
; `Blocks Common.help_secs
1515
]
1616

17-
let info = Term.info "external-lib-deps" ~doc ~man
17+
let info = Cmd.info "external-lib-deps" ~doc ~man
1818

1919
let term =
2020
Term.ret
@@ -25,4 +25,4 @@ let term =
2525
and+ _ = Arg.(value & flag & info [ "sexp" ] ~doc:{|unused|}) in
2626
`Error (false, "This subcommand is no longer implemented.")
2727

28-
let command = (term, info)
28+
let command = Cmd.v info term

bin/external_lib_deps.mli

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
val command : unit Cmdliner.Term.t * Cmdliner.Term.info
1+
open Import
2+
3+
val command : unit Cmd.t

bin/format_dune_file.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ let man =
1212
formatting" section in the manual.|}
1313
]
1414

15-
let info = Term.info "format-dune-file" ~doc ~man
15+
let info = Cmd.info "format-dune-file" ~doc ~man
1616

1717
let format_file ~version ~input =
1818
let with_input =
@@ -50,4 +50,4 @@ let term =
5050
let input = Option.map ~f:Arg.Path.path path_opt in
5151
format_file ~version ~input
5252

53-
let command = (term, info)
53+
let command = Cmd.v info term

bin/format_dune_file.mli

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
val command : unit Cmdliner.Term.t * Cmdliner.Term.info
1+
open Import
2+
3+
val command : unit Cmd.t

bin/help.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ let man =
102102
; Common.footer
103103
]
104104

105-
let info = Term.info "help" ~doc ~man
105+
let info = Cmd.info "help" ~doc ~man
106106

107107
let term =
108108
Term.ret
@@ -124,4 +124,4 @@ let term =
124124
|> String.concat ~sep:"\n" |> print_endline;
125125
`Ok ()
126126

127-
let command = (term, info)
127+
let command = Cmd.v info term

bin/help.mli

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
val command : unit Cmdliner.Term.t * Cmdliner.Term.info
1+
open Import
2+
3+
val command : unit Cmd.t

0 commit comments

Comments
 (0)