feat(cli): add basic ssh key support

added support for key config and support for enabling auto sign when running `use`
This commit is contained in:
ozzy committed 2026-09-13 10:33:49 -05:00
1 parent 5145ec8aea
commit 8eb2b06ab2
2 files changed
+15

No files matched your search

+14
View File
@@ -68,6 +68,9 @@ pub struct UseArgs {
/// whether or not to use it in the global context /// whether or not to use it in the global context
#[arg(short, long)] #[arg(short, long)]
pub global: bool, pub global: bool,
/// whether or not to set up commit signing using ssh key
#[arg(short, long)]
pub sign: bool,
} }
impl UseArgs { impl UseArgs {
@@ -83,6 +86,13 @@ impl UseArgs {
git::set_git_config("user.name", &profile.username, self.global)?; git::set_git_config("user.name", &profile.username, self.global)?;
git::set_git_config("user.email", &profile.email, self.global)?; git::set_git_config("user.email", &profile.email, self.global)?;
if let Some(key) = &profile.ssh_key {
git::set_git_config("user.signingkey", key, self.global)?;
}
if self.sign {
git::set_git_config("commit.gpgsign", "true", self.global)?;
git::set_git_config("gpg.format", "ssh", self.global)?;
}
Ok(()) Ok(())
} }
} }
@@ -97,6 +107,9 @@ pub struct AddArgs {
/// git user.email /// git user.email
#[arg(long)] #[arg(long)]
pub email: String, pub email: String,
/// git user.signingkey
#[arg(long)]
pub key: Option<String>,
} }
impl AddArgs { impl AddArgs {
@@ -111,6 +124,7 @@ impl AddArgs {
name: self.profile_name, name: self.profile_name,
username: self.name, username: self.name,
email: self.email, email: self.email,
ssh_key: self.key,
}); });
config::write_profile_list(profiles)?; config::write_profile_list(profiles)?;
println!("profile added"); println!("profile added");
+1
View File
@@ -12,6 +12,7 @@ pub struct Profile {
pub name: String, pub name: String,
pub username: String, pub username: String,
pub email: String, pub email: String,
pub ssh_key: Option<String>,
} }
fn get_config_dir() -> Result<PathBuf, Box<dyn Error>> { fn get_config_dir() -> Result<PathBuf, Box<dyn Error>> {