From e943408877b54ae0d3752f371c46b7aa8fd3d592 Mon Sep 17 00:00:00 2001 From: Hofer-Julian <30049909+Hofer-Julian@users.noreply.github.com> Date: Fri, 20 Sep 2024 16:54:30 +0200 Subject: [PATCH] feat: Give better info message for `pixi global sync` (#2100) It now informs you if `pixi global sync` did nothing --- src/cli/global/sync.rs | 11 ++++++++++- src/global/install.rs | 21 ++++++++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/cli/global/sync.rs b/src/cli/global/sync.rs index 85b0edf50..2ec0d87be 100644 --- a/src/cli/global/sync.rs +++ b/src/cli/global/sync.rs @@ -16,5 +16,14 @@ pub struct Args { pub async fn execute(args: Args) -> miette::Result<()> { let config = Config::with_cli_config(&args.config); - global::sync(&config, args.assume_yes).await + let updated_env = global::sync(&config, args.assume_yes).await?; + + if !updated_env { + eprintln!( + "{} Nothing to do. The pixi global installation is already up-to-date", + console::style(console::Emoji("✔ ", "")).green() + ); + } + + Ok(()) } diff --git a/src/global/install.rs b/src/global/install.rs index 6ce0a04ae..3b4f00dcf 100644 --- a/src/global/install.rs +++ b/src/global/install.rs @@ -429,7 +429,9 @@ pub(crate) fn prompt_user_to_continue( Ok(true) } -pub(crate) async fn sync(config: &Config, assume_yes: bool) -> Result<(), miette::Error> { +// Syncs the manifest with the local environment +// Returns true if the global installation had to be updated +pub(crate) async fn sync(config: &Config, assume_yes: bool) -> Result { // Create directories let bin_dir = BinDir::from_env().await?; let env_root = EnvRoot::from_env().await?; @@ -476,6 +478,8 @@ pub(crate) async fn sync(config: &Config, assume_yes: bool) -> Result<(), miette } } + let mut updated_env = false; + for (env_name, parsed_environment) in project.environments() { let specs = parsed_environment .dependencies @@ -505,8 +509,15 @@ pub(crate) async fn sync(config: &Config, assume_yes: bool) -> Result<(), miette .map(|r| r.repodata_record) .collect_vec(); - if !local_environment_matches_spec(repodata_records, &specs, parsed_environment.platform()) - { + let install_env = !local_environment_matches_spec( + repodata_records, + &specs, + parsed_environment.platform(), + ); + + updated_env |= install_env; + + if install_env { install_environment( &specs, &parsed_environment, @@ -518,7 +529,7 @@ pub(crate) async fn sync(config: &Config, assume_yes: bool) -> Result<(), miette .await?; } - expose_executables( + updated_env |= expose_executables( &env_name, &parsed_environment, specs.keys().cloned().collect(), @@ -528,7 +539,7 @@ pub(crate) async fn sync(config: &Config, assume_yes: bool) -> Result<(), miette .await?; } - Ok(()) + Ok(updated_env) } /// Checks if the local environment matches the given specifications.