Merge pull request 'Added --version and robur cli-output' (#7) from 20220407_adding_viz_version_and_robur_cli-output into main

Reviewed-on: https://git.robur.io/robur/opam-graph/pulls/7
This commit is contained in:
Reynir Björnsson 2022-07-21 11:50:13 +00:00
commit 8644ee0119
3 changed files with 44 additions and 14 deletions

View file

@ -1,4 +1,4 @@
(executable (executable
(name main) (name main)
(public_name opam_graph) (public_name opam-graph)
(libraries cmdliner logs logs.fmt fmt.cli fmt.tty logs.cli opam-graph)) (libraries cmdliner logs logs.fmt fmt.cli fmt.tty logs.cli opam-graph))

View file

@ -12,24 +12,39 @@ let read_file file =
with _ -> invalid_arg ("Error opening file " ^ file) with _ -> invalid_arg ("Error opening file " ^ file)
let jump () transitive file output_format = let jump () transitive file output_format =
let module G = Opam_graph in
let switch = read_file file in let switch = read_file file in
let data = OpamFile.SwitchExport.read_from_string switch in let data = OpamFile.SwitchExport.read_from_string switch in
match output_format with match output_format with
| `Text -> | `Text ->
let graph = Opam_graph.dependencies ~transitive data in let graph = G.dependencies ~transitive data in
Format.printf "%a" Opam_graph.pp_graph graph Format.printf "%a" G.pp_graph graph
| `Dot -> | `Dot ->
let graph = Opam_graph.dependencies ~transitive data in let graph = G.dependencies ~transitive data in
let dot = Opam_graph.Render.Dot.of_graph graph in let dot = G.Render.Dot.of_graph graph in
Format.printf "%a" Opam_graph.Render.Dot.pp dot Format.printf "%a" G.Render.Dot.pp dot
| `Dot_ui -> | `Dot_ui ->
let graph = Opam_graph.Ui.dependencies ~transitive data in let graph = G.Ui.dependencies ~transitive data in
let dot = Opam_graph.Render.Dot.of_assoc graph in let dot = G.Render.Dot.of_assoc graph in
Format.printf "%a" Opam_graph.Render.Dot.pp dot Format.printf "%a" G.Render.Dot.pp dot
| `Html -> | `Html ->
let graph = Opam_graph.Ui.dependencies ~transitive data in let graph = G.Ui.dependencies ~transitive data in
let html = Opam_graph.Render.Html.of_assoc graph in let sharing_stats =
Format.printf "%a" Opam_graph.Render.Html.pp html data
|> G.dependencies ~transitive:false
|> G.calc_sharing_stats in
let override_css = "\
.deps-svg-wrap {\
background: rgb(60, 60, 87); \
}\
"
in
let html =
G.Render.Html.of_assoc
~override_css
~sharing_stats graph
in
Format.printf "%a" G.Render.Html.pp html
let setup_log style_renderer level = let setup_log style_renderer level =
Fmt_tty.setup_std_outputs ?style_renderer (); Fmt_tty.setup_std_outputs ?style_renderer ();
@ -62,8 +77,15 @@ let file =
Arg.(required & pos 0 (some file) None & info [ ] ~doc ~docv:"FILE") Arg.(required & pos 0 (some file) None & info [ ] ~doc ~docv:"FILE")
let cmd = let cmd =
let term = Term.(const jump $ setup_log $ transitive $ file $ output_format) in let term = Term.(
let info = Cmd.info "opam_graph" ~version:"%%VERSION%%" in const jump
$ setup_log
$ transitive
$ file
$ output_format
) in
let version = Fmt.str "%d" Opam_graph.visualization_version in
let info = Cmd.info "opam-graph" ~version in
Cmd.v info term Cmd.v info term
let () = Cmd.eval cmd |> exit let () = Cmd.eval cmd |> exit

View file

@ -1,4 +1,12 @@
let visualization_version = 1
(** Remember to increment this when anything changes that can affect the
visualization, e.g.:
* algorithm change
* UI change
* certain library-dependency changes
*)
let sprintf = Printf.sprintf let sprintf = Printf.sprintf
module OSet = OpamPackage.Set module OSet = OpamPackage.Set