feat: add ability to specify custom command #56

Merged
kjuulh merged 2 commits from feat/add-ability-to-specify-custom-command into main 2025-01-08 22:45:34 +01:00
2 changed files with 38 additions and 18 deletions
Showing only changes of commit 962425c515 - Show all commits

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,25 +13,29 @@ 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 Some((first, rest)) = command_parts.split_first() else { let command_parts = command.split(' ').collect::<Vec<_>>();
return Ok(()); let Some((first, rest)) = command_parts.split_first() else {
}; return Ok(());
};
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);
tracing::info!( eprintln!("running command: {}", command);
path = path.display().to_string(),
cmd = post_update_command, tracing::info!(
"running custom post update command" path = path.display().to_string(),
); cmd = command,
let output = cmd.output().await?; "running custom post update command"
let stdout = std::str::from_utf8(&output.stdout)?; );
tracing::info!( let output = cmd.output().await?;
stdout = stdout, let stdout = std::str::from_utf8(&output.stdout)?;
"finished running custom post update command" tracing::info!(
); stdout = stdout,
"finished running custom post update command"
);
}
} }
Ok(()) Ok(())