pakker/src/cli/commands/credentials_set.rs
NotAShelf ef28bdaeb4
initial commit
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Ife1391ed23a1e7f388b1b5eca90b9ea76a6a6964
2026-02-13 00:14:46 +03:00

74 lines
1.8 KiB
Rust

use crate::{
error::{PakkerError, Result},
model::{PakkerCredentialsFile, set_keyring_secret},
};
pub fn execute(
curseforge_api_key: Option<String>,
modrinth_token: Option<String>,
github_access_token: Option<String>,
) -> Result<()> {
let mut creds = PakkerCredentialsFile::load()?;
let mut updated_any = false;
if let Some(key) = curseforge_api_key {
let key = key.trim().to_string();
if key.is_empty() {
return Err(PakkerError::InternalError(
"CurseForge API key cannot be empty".to_string(),
));
}
println!("Setting CurseForge API key...");
set_keyring_secret("curseforge_api_key", &key)?;
creds.curseforge_api_key = Some(key);
updated_any = true;
}
if let Some(token) = modrinth_token {
let token = token.trim().to_string();
if token.is_empty() {
return Err(PakkerError::InternalError(
"Modrinth token cannot be empty".to_string(),
));
}
println!("Setting Modrinth token...");
set_keyring_secret("modrinth_token", &token)?;
creds.modrinth_token = Some(token);
updated_any = true;
}
if let Some(token) = github_access_token {
let token = token.trim().to_string();
if token.is_empty() {
return Err(PakkerError::InternalError(
"GitHub access token cannot be empty".to_string(),
));
}
println!("Setting GitHub access token...");
set_keyring_secret("github_access_token", &token)?;
creds.github_access_token = Some(token);
updated_any = true;
}
if !updated_any {
println!(
"No credentials provided. Use --cf-api-key, --modrinth-token, or \
--gh-access-token."
);
return Ok(());
}
creds.save()?;
println!("Credentials saved.");
println!(
"Credentials file: {}",
PakkerCredentialsFile::get_path()?.display()
);
println!("Keyring service: pakker");
Ok(())
}