···
as determined by command-line arguments and environment variables. *)
+
(** [term app_name fs ?config ?data ?cache ?state ?runtime ()] creates a
+
Cmdliner term for XDG directory configuration.
+
This function generates a Cmdliner term that handles XDG directory
configuration through both command-line flags and environment variables,
+
and directly returns the XDG context. Individual directory flags can be
+
disabled by passing [false] for the corresponding optional parameter.
@param app_name The application name (used for environment variable prefixes)
@param fs The Eio filesystem to use for path resolution
+
@param config Include [--config-dir] flag (default: true)
+
@param data Include [--data-dir] flag (default: true)
+
@param cache Include [--cache-dir] flag (default: true)
+
@param state Include [--state-dir] flag (default: true)
+
@param runtime Include [--runtime-dir] flag (default: true)
{b Generated Command-line Flags:}
+
Only the flags for enabled directories are generated:
+
- [--config-dir DIR]: Override configuration directory (if [config=true])
+
- [--data-dir DIR]: Override data directory (if [data=true])
+
- [--cache-dir DIR]: Override cache directory (if [cache=true])
+
- [--state-dir DIR]: Override state directory (if [state=true])
+
- [--runtime-dir DIR]: Override runtime directory (if [runtime=true])
{b Environment Variable Precedence:}
For each directory type, the following precedence applies:
+
+ Command-line flag (e.g., [--config-dir]) - if enabled
+ Application-specific variable (e.g., [MYAPP_CONFIG_DIR])
+ XDG standard variable (e.g., [XDG_CONFIG_HOME])
+
{b Example - All directories:}
+
let xdg_term = Cmd.term "myapp" env#fs () in
+
let main_term = Term.(const main $ xdg_term $ other_args) in
+
{b Example - Only cache directory:}
+
let xdg_term = Cmd.term "myapp" env#fs
+
~config:false ~data:false ~state:false ~runtime:false () in
let main_term = Term.(const main $ xdg_term $ other_args) in
+
val term : string -> Eio.Fs.dir_ty Eio.Path.t ->
+
?config:bool -> ?data:bool -> ?cache:bool -> ?state:bool -> ?runtime:bool ->
+
unit -> (xdg_t * t) Cmdliner.Term.t
+
(** [cache_term app_name] creates a Cmdliner term that provides just the cache
+
directory path as a string, respecting XDG precedence.
+
This is a convenience function for applications that only need cache
+
directory configuration. It returns the resolved cache directory path
+
directly as a string, suitable for use in other Cmdliner terms.
+
@param app_name The application name (used for environment variable prefixes)
+
{b Generated Command-line Flag:}
+
- [--cache-dir DIR]: Override cache directory
+
{b Environment Variable Precedence:}
+
+ Command-line flag ([--cache-dir])
+
+ Application-specific variable (e.g., [MYAPP_CACHE_DIR])
+
+ XDG standard variable ([XDG_CACHE_HOME])
+
+ Default value ([$HOME/.cache/{app_name}])
+
let cache_dir_term = Xdge.Cmd.cache_term "myapp" in
+
let main cache_dir other_args =
+
(* use cache_dir as a string path *)
+
let main_term = Term.(const main $ cache_dir_term $ other_args) in
+
val cache_term : string -> string Cmdliner.Term.t
(** [env_docs app_name] generates documentation for environment variables.