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:
2 files changed
+15
No files matched your search
+14
@@ -68,6 +68,9 @@ pub struct UseArgs {
|
||||
/// whether or not to use it in the global context
|
||||
#[arg(short, long)]
|
||||
pub global: bool,
|
||||
/// whether or not to set up commit signing using ssh key
|
||||
#[arg(short, long)]
|
||||
pub sign: bool,
|
||||
}
|
||||
|
||||
impl UseArgs {
|
||||
@@ -83,6 +86,13 @@ impl UseArgs {
|
||||
|
||||
git::set_git_config("user.name", &profile.username, 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(())
|
||||
}
|
||||
}
|
||||
@@ -97,6 +107,9 @@ pub struct AddArgs {
|
||||
/// git user.email
|
||||
#[arg(long)]
|
||||
pub email: String,
|
||||
/// git user.signingkey
|
||||
#[arg(long)]
|
||||
pub key: Option<String>,
|
||||
}
|
||||
|
||||
impl AddArgs {
|
||||
@@ -111,6 +124,7 @@ impl AddArgs {
|
||||
name: self.profile_name,
|
||||
username: self.name,
|
||||
email: self.email,
|
||||
ssh_key: self.key,
|
||||
});
|
||||
config::write_profile_list(profiles)?;
|
||||
println!("profile added");
|
||||
|
||||
@@ -12,6 +12,7 @@ pub struct Profile {
|
||||
pub name: String,
|
||||
pub username: String,
|
||||
pub email: String,
|
||||
pub ssh_key: Option<String>,
|
||||
}
|
||||
|
||||
fn get_config_dir() -> Result<PathBuf, Box<dyn Error>> {
|
||||
|
||||
Reference in new issue
Block a user