add ability to specify multiple commands
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing

This commit is contained in:
Kasper Juul Hermansen 2025-01-08 22:42:35 +01:00
parent 708f8d6388
commit 962425c515
Signed by: kjuulh
SSH Key Fingerprint: SHA256:RjXh0p7U6opxnfd3ga/Y9TCo18FYlHFdSpRIV72S/QM
2 changed files with 38 additions and 18 deletions

View File

@ -20,7 +20,23 @@ pub struct Settings {
#[serde(default)] #[serde(default)]
pub cache: Cache, pub cache: Cache,
pub post_update_command: Option<String>, pub post_update_command: Option<PostUpdateCommand>,
}
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[serde(untagged)]
pub enum PostUpdateCommand {
Single(String),
Multiple(Vec<String>),
}
impl PostUpdateCommand {
pub fn get_commands(&self) -> Vec<String> {
match self.clone() {
PostUpdateCommand::Single(item) => vec![item],
PostUpdateCommand::Multiple(items) => items,
}
}
} }
#[derive(Debug, Default, Serialize, Deserialize, PartialEq, Clone)] #[derive(Debug, Default, Serialize, Deserialize, PartialEq, Clone)]

View File

@ -13,7 +13,8 @@ impl CustomCommand {
pub async fn execute_post_update_command(&self, path: &Path) -> anyhow::Result<()> { pub async fn execute_post_update_command(&self, path: &Path) -> anyhow::Result<()> {
if let Some(post_update_command) = &self.config.settings.post_update_command { if let Some(post_update_command) = &self.config.settings.post_update_command {
let command_parts = post_update_command.split(' ').collect::<Vec<_>>(); for command in post_update_command.get_commands() {
let command_parts = command.split(' ').collect::<Vec<_>>();
let Some((first, rest)) = command_parts.split_first() else { let Some((first, rest)) = command_parts.split_first() else {
return Ok(()); return Ok(());
}; };
@ -21,9 +22,11 @@ impl CustomCommand {
let mut cmd = tokio::process::Command::new(first); let mut cmd = tokio::process::Command::new(first);
cmd.args(rest).current_dir(path); cmd.args(rest).current_dir(path);
eprintln!("running command: {}", command);
tracing::info!( tracing::info!(
path = path.display().to_string(), path = path.display().to_string(),
cmd = post_update_command, cmd = command,
"running custom post update command" "running custom post update command"
); );
let output = cmd.output().await?; let output = cmd.output().await?;
@ -33,6 +36,7 @@ impl CustomCommand {
"finished running custom post update command" "finished running custom post update command"
); );
} }
}
Ok(()) Ok(())
} }