diff --git a/bin/monrun/src/sync/mod.rs b/bin/monrun/src/sync/mod.rs index ea31a4948..9619dd125 100644 --- a/bin/monrun/src/sync/mod.rs +++ b/bin/monrun/src/sync/mod.rs @@ -36,6 +36,29 @@ pub async fn run_sync(path: &Path) -> anyhow::Result<()> { let (user_group_creates, user_group_updates) = user_group::get_updates(resources.user_groups).await?; + if server_template_creates.is_empty() + && server_template_updates.is_empty() + && server_creates.is_empty() + && server_updates.is_empty() + && deployment_creates.is_empty() + && deployment_updates.is_empty() + && build_creates.is_empty() + && build_updates.is_empty() + && builder_creates.is_empty() + && builder_updates.is_empty() + && alerter_creates.is_empty() + && alerter_updates.is_empty() + && repo_creates.is_empty() + && repo_updates.is_empty() + && procedure_creates.is_empty() + && procedure_updates.is_empty() + && user_group_creates.is_empty() + && user_group_updates.is_empty() + { + println!("\nNothing to do. Exiting."); + return Ok(()); + } + wait_for_enter("CONTINUE")?; // No deps diff --git a/bin/monrun/src/sync/resources/mod.rs b/bin/monrun/src/sync/resources/mod.rs index e16666e3e..2f65f1917 100644 --- a/bin/monrun/src/sync/resources/mod.rs +++ b/bin/monrun/src/sync/resources/mod.rs @@ -77,14 +77,19 @@ pub trait ResourceSync { match map.get(&resource.name).map(|s| s.id.clone()) { Some(id) => { // Get the full original config for the resource. - let original = Self::get(id.clone()).await?.config; + let original = Self::get(id.clone()).await?; // Minimizes updates through diffing. resource.config = - Self::minimize_update(original, resource.config).await?; + Self::minimize_update(original.config, resource.config) + .await?; - // Only try to update if there are any fields to update. - if !resource.config.is_none() { + // Only try to update if there are any fields to update, + // or a change to tags / description + if !resource.config.is_none() + || resource.description != original.description + || resource.tags != original.tags + { to_update.push((id, resource)); } } @@ -99,19 +104,24 @@ pub trait ResourceSync { if !to_create.is_empty() { if quiet { println!( - "\n{} {}: {:#?}", + "\n{}s {}: {:#?}", Self::display(), "TO CREATE".green(), - to_create - .iter() - .map(|item| item.name.as_str()) - .collect::>() + to_create.iter().map(|item| item.name.as_str()) ); } else { println!( - "\n{} {}:\n{to_create:#?}", - Self::display(), - "TO CREATE".green() + "\n{}", + to_create + .iter() + .map(|r| format!( + "{}: {}: {}: {r:#?}", + "CREATE".green(), + Self::display(), + r.name.bold().green(), + )) + .collect::>() + .join("\n\n") ); } } @@ -119,21 +129,24 @@ pub trait ResourceSync { if !to_update.is_empty() { if quiet { println!( - "\n{} {}: {}", + "\n{}s {}: {:#?}", Self::display(), "TO UPDATE".blue(), - to_update - .iter() - .map(|(_, item)| item.name.as_str()) - .collect::>() - .join(", ") + to_update.iter().map(|(_, item)| item.name.as_str()) ); } else { println!( - "\n{} {}:\n{:#?}", - Self::display(), - "TO UPDATE".blue(), - to_update.iter().map(|(_, r)| r).collect::>() + "\n{}", + to_update + .iter() + .map(|(_, r)| format!( + "{}: {}: {}: {r:#?}", + "UPDATE".blue(), + Self::display(), + r.name.bold().green(), + )) + .collect::>() + .join("\n\n") ); } }