diff --git a/crates/gitnow/src/config.rs b/crates/gitnow/src/config.rs index 2664fcb..e796999 100644 --- a/crates/gitnow/src/config.rs +++ b/crates/gitnow/src/config.rs @@ -20,7 +20,23 @@ pub struct Settings { #[serde(default)] pub cache: Cache, - pub post_update_command: Option, + pub post_update_command: Option, +} + +#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)] +#[serde(untagged)] +pub enum PostUpdateCommand { + Single(String), + Multiple(Vec), +} + +impl PostUpdateCommand { + pub fn get_commands(&self) -> Vec { + match self.clone() { + PostUpdateCommand::Single(item) => vec![item], + PostUpdateCommand::Multiple(items) => items, + } + } } #[derive(Debug, Default, Serialize, Deserialize, PartialEq, Clone)] diff --git a/crates/gitnow/src/custom_command.rs b/crates/gitnow/src/custom_command.rs index 5643786..b47f07b 100644 --- a/crates/gitnow/src/custom_command.rs +++ b/crates/gitnow/src/custom_command.rs @@ -13,25 +13,29 @@ impl CustomCommand { pub async fn execute_post_update_command(&self, path: &Path) -> anyhow::Result<()> { if let Some(post_update_command) = &self.config.settings.post_update_command { - let command_parts = post_update_command.split(' ').collect::>(); - let Some((first, rest)) = command_parts.split_first() else { - return Ok(()); - }; + for command in post_update_command.get_commands() { + let command_parts = command.split(' ').collect::>(); + let Some((first, rest)) = command_parts.split_first() else { + return Ok(()); + }; - let mut cmd = tokio::process::Command::new(first); - cmd.args(rest).current_dir(path); + let mut cmd = tokio::process::Command::new(first); + cmd.args(rest).current_dir(path); - tracing::info!( - path = path.display().to_string(), - cmd = post_update_command, - "running custom post update command" - ); - let output = cmd.output().await?; - let stdout = std::str::from_utf8(&output.stdout)?; - tracing::info!( - stdout = stdout, - "finished running custom post update command" - ); + eprintln!("running command: {}", command); + + tracing::info!( + path = path.display().to_string(), + cmd = command, + "running custom post update command" + ); + let output = cmd.output().await?; + let stdout = std::str::from_utf8(&output.stdout)?; + tracing::info!( + stdout = stdout, + "finished running custom post update command" + ); + } } Ok(())