Skip to content

Commit

Permalink
Allow setting path to config file via env args (#611)
Browse files Browse the repository at this point in the history
* Enable passing path to config file via env args

* Remove println

* Update comment

* Remove unwanted file

* Update CHANGELOG
  • Loading branch information
sandreae authored Jun 3, 2024
1 parent 5516f82 commit b162439
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Allow setting config file path via environment variables [#611](https://github.com/p2panda/aquadoggo/pull/611)

## [0.7.1]

### Added
Expand Down
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
5 changes: 3 additions & 2 deletions aquadoggo_cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ type ConfigFilePath = Option<PathBuf>;
/// Returns a partly unchecked configuration object which results from all of these sources. It
/// still needs to be converted for aquadoggo as it might still contain invalid values.
pub fn load_config() -> Result<(ConfigFilePath, ConfigFile)> {
// Parse command line arguments first to get optional config file path
// Parse command line arguments and CONFIG environment variable first to get optional config
// file path
let cli = Cli::parse();

// Determine if a config file path was provided or if we should look for it in common locations
Expand Down Expand Up @@ -74,7 +75,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 b162439

Please sign in to comment.