Skip to content
Snippets Groups Projects
Verified Commit 7053f561 authored by Eduardo Trujillo's avatar Eduardo Trujillo
Browse files

feat(config): Add basic XDG config file path support

parent 29fcf525
No related branches found
No related tags found
No related merge requests found
Pipeline #287 failed
......@@ -40,6 +40,12 @@ version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "3.1.0"
......@@ -67,6 +73,27 @@ dependencies = [
"serde",
"thiserror",
"toml",
"xdg",
]
[[package]]
name = "dirs"
version = "4.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059"
dependencies = [
"dirs-sys",
]
[[package]]
name = "dirs-sys"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6"
dependencies = [
"libc",
"redox_users",
"winapi",
]
[[package]]
......@@ -97,6 +124,17 @@ dependencies = [
"version_check",
]
[[package]]
name = "getrandom"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31"
dependencies = [
"cfg-if 1.0.0",
"libc",
"wasi",
]
[[package]]
name = "hashbrown"
version = "0.9.1"
......@@ -151,9 +189,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.81"
version = "0.2.137"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb"
checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89"
[[package]]
name = "linked-hash-map"
......@@ -167,7 +205,7 @@ version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b"
dependencies = [
"cfg-if",
"cfg-if 0.1.10",
]
[[package]]
......@@ -255,6 +293,26 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "redox_syscall"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
dependencies = [
"bitflags",
]
[[package]]
name = "redox_users"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b"
dependencies = [
"getrandom",
"redox_syscall",
"thiserror",
]
[[package]]
name = "regex"
version = "1.4.2"
......@@ -399,6 +457,12 @@ version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "winapi"
version = "0.3.9"
......@@ -430,6 +494,15 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "xdg"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c4583db5cbd4c4c0303df2d15af80f0539db703fa1c68802d4cbbd2dd0f88f6"
dependencies = [
"dirs",
]
[[package]]
name = "yaml-rust"
version = "0.4.5"
......
......@@ -13,9 +13,11 @@ clap = "3.1"
pretty_env_logger = "0.4"
figment = { version = "0.10", features = ["toml", "env"] }
lazy_static = { version = "1.4", optional = true }
xdg = { version = "2.4", optional = true }
[features]
default = ["config-yaml", "config-json", "thread"]
default = ["config-yaml", "config-json", "thread", "xdg"]
config-yaml = ["figment/yaml"]
config-json = ["figment/json"]
thread = ["lazy_static"]
\ No newline at end of file
thread = ["lazy_static"]
xdg = ["dep:xdg"]
\ No newline at end of file
......@@ -14,6 +14,8 @@ use figment::{
use log::{debug, info};
use serde::{de::DeserializeOwned, Serialize};
use thiserror::Error;
#[cfg(feature = "xdg")]
use xdg;
use crate::str::to_train_case;
......@@ -209,6 +211,17 @@ fn get_name_config_path(application_name: &str, format: &ConfigFileFormat) -> Pa
config_path
}
#[cfg(feature = "xdg")]
pub fn get_name_xdg_config_path(application_name: &str, format: &ConfigFileFormat) -> Option<PathBuf> {
let xdg_dirs = xdg::BaseDirectories::with_prefix(application_name).ok();
if let Some(xdg_dirs) = xdg_dirs {
xdg_dirs.find_config_file(get_default_filename_from_format(format))
} else {
None
}
}
fn infer_format_from_path<P: AsRef<Path>>(path: P) -> Result<ConfigFileFormat, ConfigError> {
match path.as_ref().extension() {
Some(extension) => match extension.to_str() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment