package xdge
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Module Xdge.CmdSource
The type of the outer XDG context
Cmdliner integration for XDG directory configuration.
This module provides integration with the Cmdliner library, allowing XDG directories to be configured via command-line arguments while respecting the precedence of environment variables.
Type of XDG configuration gathered from command-line and environment.
This contains all XDG directory paths along with their sources, as determined by command-line arguments and environment variables.
type dir = [ | `Config(*User configuration files
*)| `Cache(*User-specific cached data
*)| `Data(*User-specific application data
*)| `State(*User-specific state data (logs, history, etc.)
*)| `Runtime(*User-specific runtime files (sockets, pipes, etc.)
*)
]XDG directory types for specifying which directories an application needs.
These allow applications to declare which XDG directories they use, enabling runtime systems to only provide the requested directories.
val term :
string ->
Eio.Fs.dir_ty Eio.Path.t ->
?dirs:dir list ->
unit ->
(xdg_t * t) Cmdliner.Term.tterm app_name fs ?dirs () 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. Only command-line flags for the requested directories are generated.
Generated Command-line Flags: Only the flags for requested directories are generated:
--config-dir DIR: Override configuration directory (if`Configin dirs)--data-dir DIR: Override data directory (if`Datain dirs)--cache-dir DIR: Override cache directory (if`Cachein dirs)--state-dir DIR: Override state directory (if`Statein dirs)--runtime-dir DIR: Override runtime directory (if`Runtimein dirs)
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) - Default value
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.
Generated Command-line Flag:
--cache-dir DIR: Override cache directory
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})
env_docs app_name generates documentation for environment variables.
Returns a formatted string documenting all environment variables that affect XDG directory configuration for the given application. This is useful for generating man pages or help text.
Included Information:
- Configuration precedence rules
- Application-specific environment variables
- XDG standard environment variables
- Default values for each directory type
pp ppf config pretty prints a Cmdliner configuration.
This function formats the configuration showing each directory path along with its source, which is helpful for debugging configuration issues or displaying the current configuration to users.