Skip to content

Commit

Permalink
Enable passing path to config file via env args
Browse files Browse the repository at this point in the history
  • Loading branch information
sandreae committed Jun 3, 2024
1 parent 5516f82 commit 6039788
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion aquadoggo_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ doc = false

[dependencies]
anyhow = "1.0.62"
clap = { version = "4.1.8", features = ["derive", "cargo"] }
clap = { version = "4.1.8", features = ["derive", "cargo", "env"] }
colored = "2.0.4"
directories = "5.0.1"
env_logger = "0.9.0"
Expand Down
1 change: 1 addition & 0 deletions aquadoggo_cli/XXX
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
73bd83d5d1c678944ae009aa1eaff143dc09dc965419167570f8c942b7c18912
6 changes: 5 additions & 1 deletion aquadoggo_cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub fn load_config() -> Result<(ConfigFilePath, ConfigFile)> {
// Parse command line arguments first to get optional config file path
let cli = Cli::parse();

println!("{:#?}", cli);

// Determine if a config file path was provided or if we should look for it in common locations
let config_file_path: ConfigFilePath = match &cli.config {
Some(path) => {
Expand All @@ -48,6 +50,8 @@ pub fn load_config() -> Result<(ConfigFilePath, ConfigFile)> {
figment = figment.merge(Toml::file(path));
}

println!("{:#?}", Env::raw().filter(|k| k == "CONFIG"));

let config = figment
.merge(Env::raw())
.merge(Serialized::defaults(cli))
Expand All @@ -74,7 +78,7 @@ struct Cli {
/// When not set the program will try to find a `config.toml` file in the same folder the
/// program is executed in and otherwise in the regarding operation systems XDG config
/// directory ("$HOME/.config/aquadoggo/config.toml" on Linux).
#[arg(short = 'c', long, value_name = "PATH")]
#[arg(short = 'c', long, value_name = "PATH", env)]
#[serde(skip_serializing_if = "Option::is_none")]
config: Option<PathBuf>,

Expand Down

0 comments on commit 6039788

Please sign in to comment.