My agentic slop goes here. Not intended for anyone else!
1(** Batteries-included CLI runner for Eio applications *)
2
3(** {1 Running Applications} *)
4
5(* Batteries-included run with XDG and optional keyeio *)
6let run ?(use_keyeio=true) ~info ~app_name ~service main_term =
7 let open Cmdliner in
8
9 let run_main main profile_name_opt key_file_opt =
10 (* Initialize RNG with default entropy source *)
11 let () = Mirage_crypto_rng_unix.use_default () in
12
13 Eio_main.run @@ fun env ->
14
15 (* Create xdg context *)
16 let xdg = Xdge.create env#fs app_name in
17
18 (* Load keyeio profile if requested *)
19 let profile =
20 if not use_keyeio then
21 (* Create empty profile when keyeio is not needed *)
22 Keyeio.Profile.empty
23 else
24 (* Load from keyeio *)
25 let keyeio_ctx = Keyeio.create xdg in
26 let profile_name = Option.value profile_name_opt ~default:"default" in
27
28 match key_file_opt with
29 | Some _path ->
30 (* TODO: Load from specified file *)
31 failwith "Direct file loading not yet supported in eiocmd (use --profile instead)"
32 | None ->
33 (* Load from XDG directory *)
34 match Keyeio.load_service keyeio_ctx ~service with
35 | Ok svc ->
36 (match Keyeio.Service.get_profile svc profile_name with
37 | Some prof -> prof
38 | None ->
39 failwith (Printf.sprintf "Profile '%s' not found in service '%s'"
40 profile_name service))
41 | Error (`Msg msg) -> failwith msg
42 in
43
44 main env xdg profile
45 in
46
47 (* Add profile and key-file flags only if using keyeio *)
48 let profile_flag =
49 if use_keyeio then
50 let doc = Printf.sprintf "Profile name to use for %s service" service in
51 Arg.(value & opt (some string) None & info [ "profile" ] ~docv:"NAME" ~doc)
52 else
53 Term.const None
54 in
55 let key_file_flag =
56 if use_keyeio then
57 let doc = Printf.sprintf "Override with direct path to %s key file" service in
58 Arg.(value & opt (some file) None & info [ "key-file" ] ~docv:"FILE" ~doc)
59 else
60 Term.const None
61 in
62
63 (* Compose with main term and add logging setup *)
64 let term =
65 let open Term.Syntax in
66 let+ main = main_term
67 and+ log_level = Logs_cli.level ()
68 and+ profile_name_opt = profile_flag
69 and+ key_file_opt = key_file_flag in
70 Logs.set_reporter (Logs_fmt.reporter ());
71 Logs.set_level log_level;
72 run_main main profile_name_opt key_file_opt
73 in
74 Cmd.v info term