diff --git a/src/main.rs b/src/main.rs index fab46c1..cf04f40 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,8 +34,11 @@ enum Command { /// Format a patch. alias "p" #[command(alias = "p")] FormatPatch(FormatPatch), + /// List all currently known patch series #[command(alias = "ls")] List(List), + /// Send a patch series by mail + Send(Send), } #[derive(Args, Debug)] @@ -44,6 +47,18 @@ struct List { verbose: bool, } +#[derive(Args, Debug)] +struct Send { + #[arg( + short, + long, + help = "Version of the patchset to set. Defaults to the latest version" + )] + version: Option, + #[arg(help = "Patch series to send")] + series: String, +} + #[derive(Args, Debug)] struct FormatPatch { #[arg(short, long, help = "Branch to use (defaults to the current branch)")] @@ -75,6 +90,7 @@ struct FormatPatch { #[derive(Debug, serde::Deserialize)] struct GsmConfig { + sendmail_args: Option>, editor: String, repo_url_base: String, component: Option, @@ -475,6 +491,29 @@ fn main() -> Result<()> { } } + Ok(()) + } + Command::Send(send) => { + let branch_dir = patch_dir.join(&send.series); + let version = match send.version { + Some(v) => v, + None => match latest_version(&branch_dir)? { + None => return Err(miette!("No patch set for the branch {}", send.series)), + Some(v) => v, + }, + }; + + let version_dir = &branch_dir.join(&version.to_string()); + let version_dir = version_dir.to_str().ok_or(miette!("Path is not UTF-8"))?; + + let mut sendmail_args = vec!["send-email"]; + if let Some(args) = &config.sendmail_args { + sendmail_args.extend(args.iter().map(|s| s.deref())) + } + sendmail_args.push(version_dir); + + git_cd(&sendmail_args).wrap_err("Could not send mails")?; + Ok(()) } }