mte/tools/offline.ml

39 lines
1.1 KiB
OCaml
Raw Normal View History

2025-11-28 11:08:43 +01:00
let download ~base_url ~output_file =
let open Bos in
let uri =
Uri.with_path (Uri.of_string base_url) "/management/keys/" |> Uri.to_string
in
let wget = Cmd.(v "wget" % "-O" % output_file % uri) in
OS.Cmd.run wget
(* CLI *)
open Cmdliner
open Cmdliner.Term.Syntax
let output =
let doc = "File to save data to be signed." in
Arg.(
value & opt filepath "management_keys.json" & info [ "o"; "output" ] ~doc)
let base_url =
let doc = "Base url of the exchange." in
Arg.(value & opt string "http://localhost:3434/" & info [ "base-url" ] ~doc)
let download_cmd =
let doc = "Downloads /management/keys/" in
let man =
[ `S Manpage.s_description; `P "$(cmd) download /management/keys." ]
in
Cmd.make (Cmd.info "offline" ~version:"%%VERSION%%" ~doc ~man)
@@
let+ output_file = output and+ base_url = base_url in
match download ~base_url ~output_file with
| Error (`Msg err) ->
Fmt.epr "Download failure: %s@." err;
exit 1
| Ok () -> ()
let main () = Cmd.eval download_cmd
let () = if !Sys.interactive then () else exit (main ())