feat: add --change-key flag to update API key
This commit is contained in:
@@ -19,4 +19,6 @@ pub struct Args {
|
|||||||
|
|
||||||
#[arg(long, help = "Undo the last file organization")]
|
#[arg(long, help = "Undo the last file organization")]
|
||||||
pub undo: bool,
|
pub undo: bool,
|
||||||
|
#[arg(long, help = "Change api key")]
|
||||||
|
pub change_key: bool,
|
||||||
}
|
}
|
||||||
|
|||||||
10
src/main.rs
10
src/main.rs
@@ -3,6 +3,7 @@ use noentropy::cli::{
|
|||||||
Args,
|
Args,
|
||||||
orchestrator::{handle_organization, handle_undo},
|
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};
|
use noentropy::settings::{get_or_prompt_config, get_or_prompt_download_folder};
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@@ -14,6 +15,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
handle_undo(args, download_path).await?;
|
handle_undo(args, download_path).await?;
|
||||||
return Ok(());
|
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()?;
|
let config = get_or_prompt_config()?;
|
||||||
|
|
||||||
|
|||||||
@@ -121,6 +121,21 @@ pub fn get_or_prompt_api_key() -> Result<String, Box<dyn std::error::Error>> {
|
|||||||
Ok(api_key)
|
Ok(api_key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn change_and_prompt_api_key() -> Result<String, Box<dyn std::error::Error>> {
|
||||||
|
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<PathBuf, Box<dyn std::error::Error>> {
|
pub fn get_or_prompt_download_folder() -> Result<PathBuf, Box<dyn std::error::Error>> {
|
||||||
if let Ok(config) = Config::load()
|
if let Ok(config) = Config::load()
|
||||||
&& !config.download_folder.as_os_str().is_empty()
|
&& !config.download_folder.as_os_str().is_empty()
|
||||||
|
|||||||
Reference in New Issue
Block a user