this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

more

+104 -149
+3 -4
xdg-eio/dune-project
··· 21 21 variable overrides and Cmdliner integration.") 22 22 (depends 23 23 (ocaml (>= 5.1.0)) 24 - (dune (>= 3.19)) 25 - (eio (>= 1.0)) 26 - (eio_main (>= 1.0)) 24 + (eio (>= 1.1)) 25 + eio_main 27 26 (xdg (>= 3.9.0)) 28 27 (cmdliner (>= 1.2.0)) 29 - (fmt (>= 0.9.0)) 28 + (fmt (>= 0.11.0)) 30 29 (odoc :with-doc) 31 30 (alcotest (and :with-test (>= 1.7.0)))))
+9 -13
xdg-eio/example/xdg_example.ml
··· 1 - let run env app_name config = 2 - let xdg = Xdge.Cmd.of_t env#fs app_name config in 1 + let run (xdg,cfg) = 3 2 Fmt.pr 4 3 "%a@.%a@.@.%a@.%a@." 5 4 Fmt.(styled `Bold string) 6 5 "=== Cmdliner Config ===" 7 6 Xdge.Cmd.pp 8 - config 7 + cfg 9 8 Fmt.(styled `Bold string) 10 9 "=== XDG Directories ===" 11 10 (Xdge.pp ~brief:false ~sources:true) 12 11 xdg 13 - ;; 14 12 15 - let main app_name config = Eio_main.run @@ fun env -> run env app_name config 13 + open Cmdliner 16 14 17 15 let () = 18 16 Fmt.set_style_renderer Fmt.stdout `Ansi_tty; 19 17 let app_name = "xdg_example" in 20 18 let doc = "Example program demonstrating XDG directory selection with Cmdliner" in 21 19 let man = 22 - [ `S Cmdliner.Manpage.s_description 20 + [ `S Manpage.s_description 23 21 ; `P 24 22 "This example shows how to use the Xdge library with Cmdliner to handle XDG Base \ 25 23 Directory Specification paths with command-line and environment variable \ 26 24 overrides." 27 - ; `S Cmdliner.Manpage.s_environment 25 + ; `S Manpage.s_environment 28 26 ; `P (Xdge.Cmd.env_docs app_name) 29 27 ] 30 28 in 31 29 let info = Cmdliner.Cmd.info "xdg_example" ~version:"1.0" ~doc ~man in 32 - let term = 33 - let open Cmdliner.Term.Syntax in 34 - let+ config = Xdge.Cmd.term app_name in 35 - main app_name config 36 - in 37 - let cmd = Cmdliner.Cmd.v info term in 30 + Eio_main.run @@ fun env -> 31 + let create_xdg_term = Xdge.Cmd.term app_name env#fs in 32 + let main_term = Term.(const run $ create_xdg_term) in 33 + let cmd = Cmdliner.Cmd.v info main_term in 38 34 exit @@ Cmdliner.Cmd.eval cmd 39 35 ;;
+73 -76
xdg-eio/lib/xdge.ml
··· 285 285 ; runtime_dir : string with_source 286 286 } 287 287 288 - let term app_name = 288 + let term app_name fs = 289 289 let open Cmdliner in 290 290 let app_upper = String.uppercase_ascii app_name in 291 291 let make_dir_arg name env_suffix xdg_var default_path = ··· 322 322 | None -> { value = None; source = Default }))) 323 323 $ arg) 324 324 in 325 - let home_prefix = "~" in 325 + let home_prefix = "\\$HOME" in 326 326 let config_dir = 327 327 make_dir_arg 328 328 "config" ··· 353 353 in 354 354 let runtime_dir = make_dir_arg "runtime" "RUNTIME_DIR" "XDG_RUNTIME_DIR" None in 355 355 Term.( 356 - const (fun config_dir data_dir cache_dir state_dir runtime_dir -> 357 - { config_dir; data_dir; cache_dir; state_dir; runtime_dir }) 356 + const (fun config_dir_ws data_dir_ws cache_dir_ws state_dir_ws runtime_dir_ws -> 357 + let config = { config_dir = config_dir_ws; data_dir = data_dir_ws; cache_dir = cache_dir_ws; state_dir = state_dir_ws; runtime_dir = runtime_dir_ws } in 358 + let home_path = get_home_dir fs in 359 + let xdg_ctx = Xdg.create ~env:Sys.getenv_opt () in 360 + (* Helper to resolve directory from config with source tracking *) 361 + let resolve_from_config config_ws xdg_getter = 362 + match config_ws.value with 363 + | Some dir -> resolve_path fs home_path dir, config_ws.source 364 + | None -> 365 + let xdg_base = xdg_getter xdg_ctx in 366 + Eio.Path.(fs / xdg_base / app_name), config_ws.source 367 + in 368 + (* User directories *) 369 + let config_dir, config_dir_source = 370 + resolve_from_config config.config_dir Xdg.config_dir 371 + in 372 + let data_dir, data_dir_source = resolve_from_config config.data_dir Xdg.data_dir in 373 + let cache_dir, cache_dir_source = 374 + resolve_from_config config.cache_dir Xdg.cache_dir 375 + in 376 + let state_dir, state_dir_source = 377 + resolve_from_config config.state_dir Xdg.state_dir 378 + in 379 + (* Runtime directory *) 380 + let runtime_dir, runtime_dir_source = 381 + match config.runtime_dir.value with 382 + | Some dir -> Some (resolve_path fs home_path dir), config.runtime_dir.source 383 + | None -> 384 + ( Option.map 385 + (fun base -> Eio.Path.(fs / base / app_name)) 386 + (Xdg.runtime_dir xdg_ctx) 387 + , config.runtime_dir.source ) 388 + in 389 + (* System directories - reuse shared helper *) 390 + let config_dirs = 391 + resolve_system_dirs 392 + fs 393 + home_path 394 + app_name 395 + "CONFIG_DIRS" 396 + "XDG_CONFIG_DIRS" 397 + [ "/etc/xdg" ] 398 + in 399 + let data_dirs = 400 + resolve_system_dirs 401 + fs 402 + home_path 403 + app_name 404 + "DATA_DIRS" 405 + "XDG_DATA_DIRS" 406 + [ "/usr/local/share"; "/usr/share" ] 407 + in 408 + ensure_dir config_dir; 409 + ensure_dir data_dir; 410 + ensure_dir cache_dir; 411 + ensure_dir state_dir; 412 + Option.iter ensure_dir runtime_dir; 413 + { app_name 414 + ; config_dir 415 + ; config_dir_source 416 + ; data_dir 417 + ; data_dir_source 418 + ; cache_dir 419 + ; cache_dir_source 420 + ; state_dir 421 + ; state_dir_source 422 + ; runtime_dir 423 + ; runtime_dir_source 424 + ; config_dirs 425 + ; data_dirs 426 + }, config) 358 427 $ config_dir 359 428 $ data_dir 360 429 $ cache_dir ··· 362 431 $ runtime_dir) 363 432 ;; 364 433 365 - let of_t fs app_name config = 366 - let fs = fs in 367 - let home_path = get_home_dir fs in 368 - let xdg_ctx = Xdg.create ~env:Sys.getenv_opt () in 369 - (* Helper to resolve directory from config with source tracking *) 370 - let resolve_from_config config_ws xdg_getter = 371 - match config_ws.value with 372 - | Some dir -> resolve_path fs home_path dir, config_ws.source 373 - | None -> 374 - let xdg_base = xdg_getter xdg_ctx in 375 - Eio.Path.(fs / xdg_base / app_name), config_ws.source 376 - in 377 - (* User directories *) 378 - let config_dir, config_dir_source = 379 - resolve_from_config config.config_dir Xdg.config_dir 380 - in 381 - let data_dir, data_dir_source = resolve_from_config config.data_dir Xdg.data_dir in 382 - let cache_dir, cache_dir_source = 383 - resolve_from_config config.cache_dir Xdg.cache_dir 384 - in 385 - let state_dir, state_dir_source = 386 - resolve_from_config config.state_dir Xdg.state_dir 387 - in 388 - (* Runtime directory *) 389 - let runtime_dir, runtime_dir_source = 390 - match config.runtime_dir.value with 391 - | Some dir -> Some (resolve_path fs home_path dir), config.runtime_dir.source 392 - | None -> 393 - ( Option.map 394 - (fun base -> Eio.Path.(fs / base / app_name)) 395 - (Xdg.runtime_dir xdg_ctx) 396 - , config.runtime_dir.source ) 397 - in 398 - (* System directories - reuse shared helper *) 399 - let config_dirs = 400 - resolve_system_dirs 401 - fs 402 - home_path 403 - app_name 404 - "CONFIG_DIRS" 405 - "XDG_CONFIG_DIRS" 406 - [ "/etc/xdg" ] 407 - in 408 - let data_dirs = 409 - resolve_system_dirs 410 - fs 411 - home_path 412 - app_name 413 - "DATA_DIRS" 414 - "XDG_DATA_DIRS" 415 - [ "/usr/local/share"; "/usr/share" ] 416 - in 417 - ensure_dir config_dir; 418 - ensure_dir data_dir; 419 - ensure_dir cache_dir; 420 - ensure_dir state_dir; 421 - Option.iter ensure_dir runtime_dir; 422 - { app_name 423 - ; config_dir 424 - ; config_dir_source 425 - ; data_dir 426 - ; data_dir_source 427 - ; cache_dir 428 - ; cache_dir_source 429 - ; state_dir 430 - ; state_dir_source 431 - ; runtime_dir 432 - ; runtime_dir_source 433 - ; config_dirs 434 - ; data_dirs 435 - } 436 - ;; 437 434 438 435 let env_docs app_name = 439 436 let app_upper = String.uppercase_ascii app_name in
+12 -51
xdg-eio/lib/xdge.mli
··· 349 349 ]} *) 350 350 val pp : ?brief:bool -> ?sources:bool -> Format.formatter -> t -> unit 351 351 352 - (** The source of a configuration value, indicating how it was determined. 353 - 354 - This type tracks the provenance of directory paths, which is useful for 355 - debugging configuration issues and understanding which settings are in effect. *) 356 - type source = 357 - | Default (** XDG specification default value was used *) 358 - | Env of string (** Set via environment variable (includes variable name) *) 359 - | Cmdline (** Set via command-line argument *) 360 - 361 352 (** {1 Cmdliner Integration} *) 362 353 363 354 module Cmd : sig ··· 375 366 - Source tracking for debugging configuration issues 376 367 - Pretty printing of configuration for --help output *) 377 368 378 - (** A configuration value paired with information about its source. 379 - 380 - This type tracks both the value (if any) and where it came from, 381 - which is useful for debugging configuration issues. *) 382 - type 'a with_source = 383 - { value : 'a option (** The configuration value, if set *) 384 - ; source : source (** Where the value came from *) 385 - } 386 - 387 369 (** Complete XDG configuration gathered from command-line and environment. 388 370 389 - This record contains all XDG directory paths along with their sources, 371 + This contains all XDG directory paths along with their sources, 390 372 as determined by command-line arguments and environment variables. *) 391 - type t = 392 - { config_dir : string with_source (** Configuration directory path and source *) 393 - ; data_dir : string with_source (** Data directory path and source *) 394 - ; cache_dir : string with_source (** Cache directory path and source *) 395 - ; state_dir : string with_source (** State directory path and source *) 396 - ; runtime_dir : string with_source (** Runtime directory path and source *) 397 - } 373 + type t 398 374 399 - (** [term app_name] creates a Cmdliner term for XDG directory configuration. 375 + (** [term app_name fs] creates a Cmdliner term for XDG directory configuration. 400 376 401 377 This function generates a Cmdliner term that handles all XDG directory 402 - configuration through both command-line flags and environment variables. 378 + configuration through both command-line flags and environment variables, 379 + and directly returns the XDG context. 403 380 404 381 @param app_name The application name (used for environment variable prefixes) 382 + @param fs The Eio filesystem to use for path resolution 405 383 406 384 {b Generated Command-line Flags:} 407 385 - [--config-dir DIR]: Override configuration directory ··· 420 398 {b Example:} 421 399 {[ 422 400 let open Cmdliner in 423 - let xdg_config = Cmd.term "myapp" in 424 - let main_term = Term.(const main $ xdg_config $ other_args) in 401 + let main xdg = 402 + (* use xdg directly *) 403 + in 404 + let xdg_term = Cmd.term "myapp" env#fs in 405 + let main_term = Term.(const main $ xdg_term $ other_args) in 425 406 (* ... *) 426 407 ]} *) 427 - val term : string -> t Cmdliner.Term.t 428 - 429 - (** [of_t fs app_name config] creates an XDG context from Cmdliner configuration. 430 - 431 - This function takes the configuration gathered by {!term} and creates 432 - a fully initialized XDG context with all directories properly resolved 433 - and created. 434 - 435 - @param fs The Eio filesystem providing filesystem access 436 - @param app_name The application name (must match the one used in {!term}) 437 - @param config The configuration returned by evaluating {!term} 438 - @return A fully initialized XDG context 439 - 440 - {b Example:} 441 - {[ 442 - let main env xdg_config = 443 - let xdg = Xdg_eio.Cmd.of_t env#fs "myapp" xdg_config in 444 - (* Use xdg for application logic *) 445 - ... 446 - ]} *) 447 - val of_t : Eio.Fs.dir_ty Eio.Path.t -> string -> t -> xdg_t 408 + val term : string -> Eio.Fs.dir_ty Eio.Path.t -> (xdg_t * t) Cmdliner.Term.t 448 409 449 410 (** [env_docs app_name] generates documentation for environment variables. 450 411
+1 -1
xdg-eio/test/xdg.t
··· 319 319 --cache-dir=DIR 320 320 Override cache directory. Can also be set with 321 321 XDG_EXAMPLE_CACHE_DIR or XDG_CACHE_HOME. Default: 322 - ~/.cache/xdg_example 322 + $HOME/.cache/xdg_example 323 323 324 324 --config-dir=DIR 325 325 Override config directory. Can also be set with
+6 -4
xdg-eio/xdge.opam
··· 6 6 maintainer: ["Anil Madhavapeddy <anil@recoil.org>"] 7 7 authors: ["Anil Madhavapeddy"] 8 8 license: "ISC" 9 + homepage: "https://tangled.sh/@anil.recoil.org/ocaml-gpx" 10 + bug-reports: "https://tangled.sh/@anil.recoil.org/xgde" 9 11 depends: [ 12 + "dune" {>= "3.20"} 10 13 "ocaml" {>= "5.1.0"} 11 - "dune" {>= "3.19" & >= "3.19"} 12 - "eio" {>= "1.0"} 13 - "eio_main" {>= "1.0"} 14 + "eio" {>= "1.1"} 15 + "eio_main" 14 16 "xdg" {>= "3.9.0"} 15 17 "cmdliner" {>= "1.2.0"} 16 - "fmt" {>= "0.9.0"} 18 + "fmt" {>= "0.11.0"} 17 19 "odoc" {with-doc} 18 20 "alcotest" {with-test & >= "1.7.0"} 19 21 ]