2021-12-20 13:25:23 +00:00
|
|
|
|
|
|
|
let read_file file =
|
|
|
|
try
|
|
|
|
let fh = open_in file in
|
|
|
|
try
|
|
|
|
let content = really_input_string fh (in_channel_length fh) in
|
|
|
|
close_in_noerr fh ;
|
|
|
|
content
|
|
|
|
with _ ->
|
|
|
|
close_in_noerr fh;
|
|
|
|
invalid_arg ("Error reading file: " ^ file)
|
|
|
|
with _ -> invalid_arg ("Error opening file " ^ file)
|
|
|
|
|
|
|
|
let () =
|
|
|
|
match Sys.argv with
|
2022-01-06 13:53:36 +00:00
|
|
|
| [| _ ; output_format; file |] -> (
|
2021-12-20 13:25:23 +00:00
|
|
|
let switch = read_file file in
|
|
|
|
let data = OpamFile.SwitchExport.read_from_string switch in
|
2022-01-06 13:53:36 +00:00
|
|
|
match output_format with
|
2022-01-07 13:09:34 +00:00
|
|
|
| "text" ->
|
|
|
|
let graph = Opam_graph.dependencies data in
|
|
|
|
Format.printf "%a" Opam_graph.pp_graph graph
|
|
|
|
| "text_transitive" ->
|
|
|
|
let graph = Opam_graph.dependencies ~transitive:true data in
|
|
|
|
Format.printf "%a" Opam_graph.pp_graph graph
|
2022-01-06 13:53:36 +00:00
|
|
|
| "dot" ->
|
2022-01-07 13:09:34 +00:00
|
|
|
let graph = Opam_graph.dependencies data in
|
2022-01-11 12:47:59 +00:00
|
|
|
let dot = Opam_graph.Render.Dot.of_graph graph in
|
|
|
|
Format.printf "%a" Opam_graph.Render.Dot.pp dot
|
|
|
|
| "dot_ui" ->
|
|
|
|
let transitive = false in
|
|
|
|
let graph = Opam_graph.Ui.dependencies ~transitive data in
|
|
|
|
let dot = Opam_graph.Render.Dot.of_assoc graph in
|
|
|
|
Format.printf "%a" Opam_graph.Render.Dot.pp dot
|
|
|
|
| "dot_ui_transitive" ->
|
2022-01-10 16:49:21 +00:00
|
|
|
let transitive = true in
|
2022-01-11 12:47:59 +00:00
|
|
|
let graph = Opam_graph.Ui.dependencies ~transitive data in
|
|
|
|
let dot = Opam_graph.Render.Dot.of_assoc graph in
|
|
|
|
Format.printf "%a" Opam_graph.Render.Dot.pp dot
|
|
|
|
| "html_ui" ->
|
2022-01-10 16:49:21 +00:00
|
|
|
let transitive = false in
|
2022-01-11 12:47:59 +00:00
|
|
|
let graph = Opam_graph.Ui.dependencies ~transitive data in
|
|
|
|
let html = Opam_graph.Render.Html.of_assoc graph in
|
|
|
|
Format.printf "%a" Opam_graph.Render.Html.pp html
|
|
|
|
| "html_ui_transitive" ->
|
|
|
|
let transitive = true in
|
|
|
|
let graph = Opam_graph.Ui.dependencies ~transitive data in
|
|
|
|
let html = Opam_graph.Render.Html.of_assoc graph in
|
|
|
|
Format.printf "%a" Opam_graph.Render.Html.pp html
|
2022-01-06 13:53:36 +00:00
|
|
|
| _ -> failwith "Unsupported output format"
|
|
|
|
)
|
2021-12-20 13:25:23 +00:00
|
|
|
| _ ->
|
|
|
|
print_endline "expecting exactly one argument";
|
|
|
|
exit 1
|
|
|
|
|