diff --git a/src/cli.rs b/src/cli.rs index 7724873..84664b6 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -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, } 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"); diff --git a/src/config.rs b/src/config.rs index 7229606..8ed2d85 100644 --- a/src/config.rs +++ b/src/config.rs @@ -12,6 +12,7 @@ pub struct Profile { pub name: String, pub username: String, pub email: String, + pub ssh_key: Option, } fn get_config_dir() -> Result> {