diff --git a/src/args.rs b/src/args.rs index 180fa30..2eedf78 100644 --- a/src/args.rs +++ b/src/args.rs @@ -5,6 +5,12 @@ use std::str::FromStr; #[clap(author, version, about, long_about = None)] #[clap(propagate_version = true)] pub struct Args { + #[clap(short, long)] + pub token: Option, + + #[clap(short, long)] + pub hostname: Option, + #[clap(subcommand)] pub command: Commands, } diff --git a/src/config/environment.rs b/src/config/environment.rs deleted file mode 100644 index 8b13789..0000000 --- a/src/config/environment.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/config/mod.rs b/src/config/mod.rs index cc39c8d..8a09a39 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1,5 +1,4 @@ mod config_file; -mod environment; use eyre::{eyre, Result}; @@ -9,12 +8,15 @@ pub struct Config { pub token: String, } -pub async fn resolve() -> Result { +pub async fn resolve(args: &crate::args::Args) -> Result { let mut config = Config { hostname: "".to_string(), token: "".to_string(), }; + /////// + // Config file + /////// let config_file = config_file::read().await?; if let Some(c) = config_file { if let Some(token) = c.token { @@ -25,6 +27,9 @@ pub async fn resolve() -> Result { } } + /////// + // Environment variables + /////// if let Ok(token) = std::env::var("HUE_TOKEN") { config.token = token; } @@ -33,8 +38,20 @@ pub async fn resolve() -> Result { config.hostname = host; } - println!("{:?}", config); + /////// + // CLI Params + /////// + if let Some(token) = &args.token { + config.token = token.clone() + } + if let Some(hostname) = &args.hostname { + config.hostname = hostname.clone() + } + + /////// + // Validate config + /////// if let Err(e) = validate_config(&config) { return Err(e); } diff --git a/src/main.rs b/src/main.rs index 4e793b9..c9992a1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,7 +10,7 @@ use eyre::{eyre, Result}; #[tokio::main] async fn main() -> Result<()> { let args = args::Args::parse(); - let config = config::resolve().await?; + let config = config::resolve(&args).await?; let res = match &args.command { args::Commands::Toggle { id, state } => {