From adfc426edee20c17ad2490593cb62b8b5ec28f51 Mon Sep 17 00:00:00 2001 From: glitchySid Date: Wed, 31 Dec 2025 21:22:46 +0530 Subject: [PATCH] feat: add --change-key flag to update API key --- src/cli/args.rs | 2 ++ src/main.rs | 10 ++++++++++ src/settings/config.rs | 15 +++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/src/cli/args.rs b/src/cli/args.rs index c5ad0e2..66e6d45 100644 --- a/src/cli/args.rs +++ b/src/cli/args.rs @@ -19,4 +19,6 @@ pub struct Args { #[arg(long, help = "Undo the last file organization")] pub undo: bool, + #[arg(long, help = "Change api key")] + pub change_key: bool, } diff --git a/src/main.rs b/src/main.rs index e40e759..7ed9490 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ use noentropy::cli::{ Args, orchestrator::{handle_organization, handle_undo}, }; +use noentropy::settings::config::change_and_prompt_api_key; use noentropy::settings::{get_or_prompt_config, get_or_prompt_download_folder}; #[tokio::main] @@ -14,6 +15,15 @@ async fn main() -> Result<(), Box> { handle_undo(args, download_path).await?; return Ok(()); } + if args.change_key { + let api_key = change_and_prompt_api_key(); + match api_key { + Ok(_key) => println!("Key saved"), + Err(e) => { + eprintln!("{e}") + } + } + } let config = get_or_prompt_config()?; diff --git a/src/settings/config.rs b/src/settings/config.rs index 2cdeaf2..557dd6e 100644 --- a/src/settings/config.rs +++ b/src/settings/config.rs @@ -121,6 +121,21 @@ pub fn get_or_prompt_api_key() -> Result> { Ok(api_key) } +pub fn change_and_prompt_api_key() -> Result> { + println!(); + println!("{}", "🔑 NoEntropy Configuration".bold().cyan()); + println!("{}", "─────────────────────────────".cyan()); + + let api_key = Prompter::prompt_api_key()?; + + let mut config = Config::load().unwrap_or_default(); + config.api_key = api_key.clone(); + config.save()?; + + println!(); + Ok(api_key) +} + pub fn get_or_prompt_download_folder() -> Result> { if let Ok(config) = Config::load() && !config.download_folder.as_os_str().is_empty()