initial commit
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Ife1391ed23a1e7f388b1b5eca90b9ea76a6a6964
This commit is contained in:
commit
ef28bdaeb4
63 changed files with 17292 additions and 0 deletions
74
src/cli/commands/credentials_set.rs
Normal file
74
src/cli/commands/credentials_set.rs
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
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(())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue