Skip to content

Commit

Permalink
Merge pull request #40 from dra27/cmdliner
Browse files Browse the repository at this point in the history
Cmdliner 1.1.0 compatibility
  • Loading branch information
dra27 authored Apr 14, 2022
2 parents 2e14208 + 963c204 commit e386bd5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
16 changes: 10 additions & 6 deletions bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ module Solver = Opam_0install.Solver.Make(Opam_0install.Switch_context)

let pp_pkg = Fmt.of_to_string OpamPackage.to_string

let select verbose with_test prefer_oldest = function
let select verbose with_test prefer_oldest spec =
let result = match spec with
| [] -> OpamConsole.error "No packages requested!"; `Bad_arguments
| spec ->
let t0 = Unix.gettimeofday () in
Expand Down Expand Up @@ -43,6 +44,8 @@ let select verbose with_test prefer_oldest = function
print_endline (Solver.diagnostics ~verbose problem);
OpamConsole.note "Eliminated all possibilities in %.2f s" (t1 -. t0);
`No_solution
in
OpamStd.Sys.get_exit_code result

open Cmdliner

Expand Down Expand Up @@ -94,10 +97,11 @@ let verbose =

let cmd =
let doc = "Select opam packages using 0install backend" in
Term.(const select $ verbose $ with_test $ prefer_oldest $ Arg.value spec),
Term.info "opam-0install" ~doc
let info = Cmd.info "opam-0install" ~doc in
let term =
Term.(const select $ verbose $ with_test $ prefer_oldest $ Arg.value spec)
in
Cmd.v info term

let () =
match Term.eval cmd with
| `Ok reason -> exit (OpamStd.Sys.get_exit_code reason)
| `Error _ | `Help | `Version as x -> Term.exit x
exit @@ Cmd.eval' cmd
2 changes: 1 addition & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ This package uses 0install's solver algorithm with opam packages.
")
(depends
(fmt (>= 0.8.7))
cmdliner
(cmdliner (>= 1.1.0))
(opam-state (>= 2.1.0~rc))
(ocaml (>= 4.08.0))
0install-solver
Expand Down
2 changes: 1 addition & 1 deletion opam-0install.opam
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ bug-reports: "https://github.com/ocaml-opam/opam-0install-solver/issues"
depends: [
"dune" {>= "2.7"}
"fmt" {>= "0.8.7"}
"cmdliner"
"cmdliner" {>= "1.1.0"}
"opam-state" {>= "2.1.0~rc"}
"ocaml" {>= "4.08.0"}
"0install-solver"
Expand Down
9 changes: 5 additions & 4 deletions test/diff.ml
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,10 @@ let new_csv = Arg.(required @@ (pos 1 (some file)) None @@ info ~docv:"NEW.csv"
let filter = Arg.(value @@ (opt (list string)) [] @@ info ~docv:"NAME" ["ignore"])
let hide_deps = Arg.(value @@ flag @@ info ~docv:"NAME" ["hide-deps"])

let cmd : unit Term.t * Term.info =
let cmd : unit Cmd.t =
let doc = "compare results from dump command" in
Term.(const diff $ filter $ hide_deps $ old_csv $ new_csv),
Term.info "diff" ~doc
let info = Cmd.info "diff" ~doc in
let term = Term.(const diff $ filter $ hide_deps $ old_csv $ new_csv) in
Cmd.v info term

let () = Term.(exit @@ eval cmd)
let () = exit @@ Cmd.eval cmd
9 changes: 5 additions & 4 deletions test/dump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,15 @@ let jobs = Arg.(required @@ (opt (some int)) None @@ info ~docv:"N" ["j"; "jobs"

let root_dir = Arg.(value @@ (opt (some dir)) None @@ info ~docv:"DIR" ["root"])

let cmd : unit Term.t * Term.info =
let cmd : unit Cmd.t =
let doc = "solve for every package in a repository" in
let man = [
`S Manpage.s_description;
`P "$(tname) performs a solve for every package name in a repository,
writing the results to a CSV file for analysis.";
] in
Term.(const run $ jobs $ root_dir $ output),
Term.info "dump" ~doc ~man
let info = Cmd.info "dump" ~doc ~man in
let term = Term.(const run $ jobs $ root_dir $ output) in
Cmd.v info term

let () = Term.(exit @@ eval cmd)
let () = exit @@ Cmd.eval cmd

0 comments on commit e386bd5

Please sign in to comment.