[feat](trx-client): add home directory config search path
Add ~/.trx-client.toml to the config file search paths, making it easy for users to place their config in the home directory. Updated search order: 1. Path specified via --config CLI argument 2. ./trx-client.toml (current directory) 3. ~/.trx-client.toml (home directory) [NEW] 4. ~/.config/trx-rs/client.toml (XDG config) 5. /etc/trx-rs/client.toml (system-wide) This provides a more standard Unix convention for user config files. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Stanislaw Grams <stanislawgrams@gmail.com>
This commit is contained in:
@@ -7,8 +7,9 @@
|
|||||||
//! Supports loading configuration from TOML files with the following search order:
|
//! Supports loading configuration from TOML files with the following search order:
|
||||||
//! 1. Path specified via `--config` CLI argument
|
//! 1. Path specified via `--config` CLI argument
|
||||||
//! 2. `./trx-client.toml` (current directory)
|
//! 2. `./trx-client.toml` (current directory)
|
||||||
//! 3. `~/.config/trx-rs/client.toml` (XDG config)
|
//! 3. `~/.trx-client.toml` (home directory)
|
||||||
//! 4. `/etc/trx-rs/client.toml` (system-wide)
|
//! 4. `~/.config/trx-rs/client.toml` (XDG config)
|
||||||
|
//! 5. `/etc/trx-rs/client.toml` (system-wide)
|
||||||
|
|
||||||
use std::net::IpAddr;
|
use std::net::IpAddr;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
@@ -452,6 +453,9 @@ impl ConfigFile for ClientConfig {
|
|||||||
fn default_search_paths() -> Vec<PathBuf> {
|
fn default_search_paths() -> Vec<PathBuf> {
|
||||||
let mut paths = Vec::new();
|
let mut paths = Vec::new();
|
||||||
paths.push(PathBuf::from("trx-client.toml"));
|
paths.push(PathBuf::from("trx-client.toml"));
|
||||||
|
if let Some(home_dir) = dirs::home_dir() {
|
||||||
|
paths.push(home_dir.join(".trx-client.toml"));
|
||||||
|
}
|
||||||
if let Some(config_dir) = dirs::config_dir() {
|
if let Some(config_dir) = dirs::config_dir() {
|
||||||
paths.push(config_dir.join("trx-rs").join("client.toml"));
|
paths.push(config_dir.join("trx-rs").join("client.toml"));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user