XDG library path support for OCaml via Eio capabilities
linux
macos
ocaml
xdg
1(*---------------------------------------------------------------------------
2 Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved.
3 SPDX-License-Identifier: ISC
4 ---------------------------------------------------------------------------*)
5
6let run (xdg, cfg) =
7 Fmt.pr "%a@.%a@.@.%a@.%a@."
8 Fmt.(styled `Bold string)
9 "=== Cmdliner Config ===" Xdge.Cmd.pp cfg
10 Fmt.(styled `Bold string)
11 "=== XDG Directories ==="
12 (Xdge.pp ~brief:false ~sources:true)
13 xdg
14
15open Cmdliner
16
17let () =
18 Fmt.set_style_renderer Fmt.stdout `Ansi_tty;
19 let app_name = "xdg_example" in
20 let doc =
21 "Example program demonstrating XDG directory selection with Cmdliner"
22 in
23 let man =
24 [
25 `S Manpage.s_description;
26 `P
27 "This example shows how to use the Xdge library with Cmdliner to \
28 handle XDG Base Directory Specification paths with command-line and \
29 environment variable overrides.";
30 `S Manpage.s_environment;
31 `P (Xdge.Cmd.env_docs app_name);
32 ]
33 in
34 let info = Cmdliner.Cmd.info "xdg_example" ~version:"1.0" ~doc ~man in
35 Eio_main.run @@ fun env ->
36 let create_xdg_term = Xdge.Cmd.term app_name env#fs () in
37 let main_term = Term.(const run $ create_xdg_term) in
38 let cmd = Cmdliner.Cmd.v info main_term in
39 exit @@ Cmdliner.Cmd.eval cmd