Skip to content

Commit

Permalink
inline cmdliner terms
Browse files Browse the repository at this point in the history
I think this style is generally preferred. This change was made purely
mechanically with:

ocamlmig replace -e '[%binding let+ __pat = [%move_def __f] in __] /// [%binding let+ __pat = __f in __]' -w
  • Loading branch information
v-gb committed Feb 6, 2025
1 parent 660d737 commit 7ee17d5
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 140 deletions.
9 changes: 4 additions & 5 deletions bin/check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ let clone_and_checkout_tag repo ~dir ~tag =

open Cmdliner

let working_tree =
let doc = "Perform the check on the current working tree." in
Arg.(value & flag & info [ "working-tree" ] ~doc)

let doc = "Check dune-release compatibility"

let man =
Expand All @@ -44,7 +40,10 @@ let term =
and+ skip_build = Cli.skip_build
and+ skip_tests = Cli.skip_tests
and+ skip_change_log = Cli.skip_change_log
and+ on_working_tree = working_tree in
and+ on_working_tree =
let doc = "Perform the check on the current working tree." in
Arg.(value & flag & info [ "working-tree" ] ~doc)
in
(let dir, clean_up =
if on_working_tree then (OS.Dir.current (), fun _ -> ())
else
Expand Down
33 changes: 14 additions & 19 deletions bin/cli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -245,28 +245,23 @@ let keep_build_dir =
(* use cmdliner evaluation error *)

let setup =
let style_renderer =
let env = Cmd.Env.info "DUNE_RELEASE_COLOR" in
Fmt_cli.style_renderer ~docs:Manpage.s_common_options ~env ()
in
let log_level =
let env = Cmd.Env.info "DUNE_RELEASE_VERBOSITY" in
Logs_cli.level ~docs:Manpage.s_common_options ~env ()
in
let cwd =
let doc = "Change to directory $(docv) before doing anything." in
let docv = "DIR" in
Arg.(
value
& opt (some path_arg) None
& info [ "C"; "pkg-dir" ] ~docs:Manpage.s_common_options ~doc ~docv)
in
Term.(
ret
(let open Syntax in
let+ style_renderer = style_renderer
and+ log_level = log_level
and+ cwd = cwd in
let+ style_renderer =
let env = Cmd.Env.info "DUNE_RELEASE_COLOR" in
Fmt_cli.style_renderer ~docs:Manpage.s_common_options ~env ()
and+ log_level =
let env = Cmd.Env.info "DUNE_RELEASE_VERBOSITY" in
Logs_cli.level ~docs:Manpage.s_common_options ~env ()
and+ cwd =
let doc = "Change to directory $(docv) before doing anything." in
let docv = "DIR" in
Arg.(
value
& opt (some path_arg) None
& info [ "C"; "pkg-dir" ] ~docs:Manpage.s_common_options ~doc ~docv)
in
Fmt_tty.setup_std_outputs ?style_renderer ();
Logs.set_level log_level;
Logs.set_reporter (Logs_fmt.reporter ~app:Fmt.stdout ());
Expand Down
41 changes: 19 additions & 22 deletions bin/config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -141,31 +141,28 @@ let man =
newly created opam-repository PR or not.";
]

let action =
let docv = "ACTION" in
let doc =
"The action to perform, either $(b,show) the config or $(b,set) a config \
field"
in
Cmdliner.Arg.(value & pos 0 string "show" & info ~doc ~docv [])

let key =
let docv = "KEY" in
let doc =
"The configuration field to set or print. For $(b,show), if no key is \
provided, the entire config will be printed."
in
Cmdliner.Arg.(value & pos 1 (some string) None & info ~doc ~docv [])

let value =
let docv = "VALUE" in
let doc = "The new field value" in
Cmdliner.Arg.(value & pos 2 (some string) None & info ~doc ~docv [])

let term =
Cmdliner.Term.(
let open Syntax in
let+ action = action and+ key_opt = key and+ value_opt = value in
let+ action =
let docv = "ACTION" in
let doc =
"The action to perform, either $(b,show) the config or $(b,set) a \
config field"
in
Cmdliner.Arg.(value & pos 0 string "show" & info ~doc ~docv [])
and+ key_opt =
let docv = "KEY" in
let doc =
"The configuration field to set or print. For $(b,show), if no key is \
provided, the entire config will be printed."
in
Cmdliner.Arg.(value & pos 1 (some string) None & info ~doc ~docv [])
and+ value_opt =
let docv = "VALUE" in
let doc = "The new field value" in
Cmdliner.Arg.(value & pos 2 (some string) None & info ~doc ~docv [])
in
let open Rresult in
(let res =
match (action, key_opt, value_opt) with
Expand Down
9 changes: 4 additions & 5 deletions bin/delegate_info.ml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
open Cmdliner
open Dune_release

let var =
let doc = "The variable to print." in
Arg.(required & pos 0 (some string) None & info [] ~doc ~docv:"VAR")

let term =
Term.(
let open Syntax in
let+ var = var in
let+ var =
let doc = "The variable to print." in
Arg.(required & pos 0 (some string) None & info [] ~doc ~docv:"VAR")
in
let open Rresult in
(let pkg = Pkg.v ~dry_run:false () in
let result =
Expand Down
8 changes: 3 additions & 5 deletions bin/help.ml
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,6 @@ let pages =

open Cmdliner

let topic =
let doc = "The topic to get help on, `topics' lists the topic." in
Arg.(value & pos 0 (some string) None & info [] ~docv:"TOPIC" ~doc)

let doc = "Show help about dune-release"
let exits = Cli.exits
let man_xrefs = [ `Main ]
Expand All @@ -267,7 +263,9 @@ let term =
ret
(let open Syntax in
let+ man_format = Arg.man_format
and+ topic = topic
and+ topic =
let doc = "The topic to get help on, `topics' lists the topic." in
Arg.(value & pos 0 (some string) None & info [] ~docv:"TOPIC" ~doc)
and+ commands = Term.choice_names in
match topic with
| None -> `Help (man_format, None)
Expand Down
25 changes: 12 additions & 13 deletions bin/lint.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@ open Dune_release

open Cmdliner

let lints =
let test = [ ("std-files", `Std_files); ("opam", `Opam) ] in
let doc =
strf
"Test to perform. $(docv) must be one of %s. If unspecified all tests \
are performed."
(Arg.doc_alts_enum test)
in
let test = Arg.enum test in
let docv = "TEST" in
Arg.(value & pos_all test Lint.all & info [] ~doc ~docv)

let doc = "Check package distribution consistency and conventions"
let sdocs = Manpage.s_common_options
let exits = Cmd.Exit.info 1 ~doc:"on lint failure" :: Cli.exits
Expand Down Expand Up @@ -51,7 +39,18 @@ let term =
and+ version = Cli.pkg_version
and+ tag = Cli.dist_tag
and+ keep_v = Cli.keep_v
and+ lints = lints in
and+ lints =
let test = [ ("std-files", `Std_files); ("opam", `Opam) ] in
let doc =
strf
"Test to perform. $(docv) must be one of %s. If unspecified all \
tests are performed."
(Arg.doc_alts_enum test)
in
let test = Arg.enum test in
let docv = "TEST" in
Arg.(value & pos_all test Lint.all & info [] ~doc ~docv)
in
Cli.handle_error
( Config.keep_v ~keep_v >>= fun keep_v ->
let pkg = Pkg.v ~dry_run ?version ~keep_v ?tag () in
Expand Down
68 changes: 34 additions & 34 deletions bin/opam.ml
Original file line number Diff line number Diff line change
Expand Up @@ -313,37 +313,6 @@ let field ~pkgs ~field_name = field pkgs field_name

open Cmdliner

let action =
let action =
[ ("descr", `Descr); ("pkg", `Pkg); ("submit", `Submit); ("field", `Field) ]
in
let doc =
strf "The action to perform. $(docv) must be one of %s."
(Arg.doc_alts_enum action)
in
let action = Arg.enum action in
Arg.(required & pos 0 (some action) None & info [] ~doc ~docv:"ACTION")

let field_arg =
let doc = "the field to output ($(b,field) action)" in
Arg.(value & pos 1 (some string) None & info [] ~doc ~docv:"FIELD")

let pkg_descr =
let doc =
"The opam descr file to use for the opam package. If absent and the opam \
file name (see $(b,--pkg-opam)) has a `.opam` extension, uses an existing \
file with the same path but a `.descr` extension. If the opam file name \
is `opam` uses a `descr` file in the same directory. If these files are \
not found a description is extracted from the the readme (see option \
$(b,--readme)) as follow: the first marked up section of the readme is \
extracted, its title is parsed according to the pattern '\\$(NAME) \
\\$(SEP) \\$(SYNOPSIS)', the body of the section is the long description. \
A few lines are filtered out: lines that start with either 'Home page:', \
'Contact:' or '%%VERSION'."
in
let docv = "FILE" in
Arg.(value & opt (some Cli.path_arg) None & info [ "pkg-descr" ] ~doc ~docv)

let doc = "Interaction with opam and the OCaml opam repository"
let sdocs = Manpage.s_common_options
let envs = []
Expand Down Expand Up @@ -396,12 +365,43 @@ let term =
and+ tag = Cli.dist_tag
and+ pkg_names = Cli.pkg_names
and+ version = Cli.pkg_version
and+ pkg_descr = pkg_descr
and+ pkg_descr =
let doc =
"The opam descr file to use for the opam package. If absent and the \
opam file name (see $(b,--pkg-opam)) has a `.opam` extension, uses an \
existing file with the same path but a `.descr` extension. If the \
opam file name is `opam` uses a `descr` file in the same directory. \
If these files are not found a description is extracted from the the \
readme (see option $(b,--readme)) as follow: the first marked up \
section of the readme is extracted, its title is parsed according to \
the pattern '\\$(NAME) \\$(SEP) \\$(SYNOPSIS)', the body of the \
section is the long description. A few lines are filtered out: lines \
that start with either 'Home page:', 'Contact:' or '%%VERSION'."
in
let docv = "FILE" in
Arg.(
value & opt (some Cli.path_arg) None & info [ "pkg-descr" ] ~doc ~docv)
and+ readme = Cli.readme
and+ change_log = Cli.change_log
and+ publish_msg = Cli.publish_msg
and+ action = action
and+ field_name = field_arg
and+ action =
let action =
[
("descr", `Descr);
("pkg", `Pkg);
("submit", `Submit);
("field", `Field);
]
in
let doc =
strf "The action to perform. $(docv) must be one of %s."
(Arg.doc_alts_enum action)
in
let action = Arg.enum action in
Arg.(required & pos 0 (some action) None & info [] ~doc ~docv:"ACTION")
and+ field_name =
let doc = "the field to output ($(b,field) action)" in
Arg.(value & pos 1 (some string) None & info [] ~doc ~docv:"FIELD")
and+ no_auto_open = Cli.no_auto_open
and+ yes = Cli.yes
and+ token = Cli.token
Expand Down
65 changes: 28 additions & 37 deletions bin/tag.ml
Original file line number Diff line number Diff line change
Expand Up @@ -75,37 +75,6 @@ let vcs_tag repo pkg tag version ~dry_run ~commit_ish ~force ~sign ~delete ~msg

open Cmdliner

let version =
let doc =
"The version tag to use. If absent, automatically extracted from the \
package's change log."
in
Arg.(value & pos 0 (some Cli.version) None & info [] ~doc ~docv:"VERSION")

let commit =
let doc = "Commit-ish $(docv) to tag." in
Arg.(value & opt string "HEAD" & info [ "commit" ] ~doc ~docv:"COMMIT-ISH")

let msg =
let doc =
"Commit message for the tag. If absent, the message 'Distribution \
$(i,VERSION)' is used."
in
Arg.(
value & opt (some string) None & info [ "m"; "message" ] ~doc ~docv:"MSG")

let sign =
let doc = "Sign the tag using the VCS's default signing key." in
Arg.(value & flag & info [ "s"; "sign" ] ~doc)

let force =
let doc = "If the tag exists, replace it rather than fail." in
Arg.(value & flag & info [ "f"; "force" ] ~doc)

let delete =
let doc = "Delete the specified tag rather than create it." in
Arg.(value & flag & info [ "d"; "delete" ] ~doc)

let doc = "Tag the package's source repository with a version"
let sdocs = Manpage.s_common_options
let exits = Cli.exits
Expand All @@ -127,12 +96,34 @@ let term =
and+ dry_run = Cli.dry_run
and+ change_log = Cli.change_log
and+ keep_v = Cli.keep_v
and+ version = version
and+ commit_ish = commit
and+ force = force
and+ sign = sign
and+ delete = delete
and+ msg = msg
and+ version =
let doc =
"The version tag to use. If absent, automatically extracted from the \
package's change log."
in
Arg.(value & pos 0 (some Cli.version) None & info [] ~doc ~docv:"VERSION")
and+ commit_ish =
let doc = "Commit-ish $(docv) to tag." in
Arg.(
value & opt string "HEAD" & info [ "commit" ] ~doc ~docv:"COMMIT-ISH")
and+ force =
let doc = "If the tag exists, replace it rather than fail." in
Arg.(value & flag & info [ "f"; "force" ] ~doc)
and+ sign =
let doc = "Sign the tag using the VCS's default signing key." in
Arg.(value & flag & info [ "s"; "sign" ] ~doc)
and+ delete =
let doc = "Delete the specified tag rather than create it." in
Arg.(value & flag & info [ "d"; "delete" ] ~doc)
and+ msg =
let doc =
"Commit message for the tag. If absent, the message 'Distribution \
$(i,VERSION)' is used."
in
Arg.(
value
& opt (some string) None
& info [ "m"; "message" ] ~doc ~docv:"MSG")
and+ yes = Cli.yes in
Config.keep_v ~keep_v
>>= (fun keep_v ->
Expand Down

0 comments on commit 7ee17d5

Please sign in to comment.