From 572dca11c3c3279d83873be19d6101cd86f26503 Mon Sep 17 00:00:00 2001 From: Tim de Jager Date: Sun, 19 May 2024 08:08:43 -0400 Subject: [PATCH 01/11] feat: allow installing multiple envs at once --- src/cli/install.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/cli/install.rs b/src/cli/install.rs index 3210fb64c..b9d68212b 100644 --- a/src/cli/install.rs +++ b/src/cli/install.rs @@ -15,7 +15,7 @@ pub struct Args { pub lock_file_usage: super::LockFileUsageArgs, #[arg(long, short)] - pub environment: Option, + pub environments: Option>, #[clap(flatten)] pub config: ConfigCli, @@ -24,9 +24,16 @@ pub struct Args { pub async fn execute(args: Args) -> miette::Result<()> { let project = Project::load_or_else_discover(args.manifest_path.as_deref())?.with_cli_config(args.config); - let environment = project.environment_from_name_or_env_var(args.environment)?; - get_up_to_date_prefix(&environment, args.lock_file_usage.into(), false).await?; + if let Some(envs) = args.environments { + for env in envs { + let environment = project.environment_from_name_or_env_var(Some(env))?; + get_up_to_date_prefix(&environment, args.lock_file_usage.into(), false).await?; + } + } else { + let environment = project.environment_from_name_or_env_var(None)?; + get_up_to_date_prefix(&environment, args.lock_file_usage.into(), false).await?; + } // Emit success eprintln!( From 666474a4880a064f855e55034597396d76225a66 Mon Sep 17 00:00:00 2001 From: Tim de Jager Date: Sun, 19 May 2024 10:37:49 -0400 Subject: [PATCH 02/11] fix: fix test --- tests/common/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 78b02f172..56a16932c 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -363,7 +363,7 @@ impl PixiControl { pub fn install(&self) -> InstallBuilder { InstallBuilder { args: Args { - environment: None, + environments: None, manifest_path: Some(self.manifest_path()), lock_file_usage: LockFileUsageArgs { frozen: false, From ec2d5a5ff85c38d04019e94f6388e6d8e606455c Mon Sep 17 00:00:00 2001 From: Tim de Jager Date: Sun, 19 May 2024 12:24:46 -0400 Subject: [PATCH 03/11] feat: allow install `-all` also added installation message --- src/cli/install.rs | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/src/cli/install.rs b/src/cli/install.rs index b9d68212b..e871b2c2a 100644 --- a/src/cli/install.rs +++ b/src/cli/install.rs @@ -2,6 +2,7 @@ use crate::config::ConfigCli; use crate::environment::get_up_to_date_prefix; use crate::Project; use clap::Parser; +use itertools::Itertools; use std::path::PathBuf; /// Install all dependencies @@ -19,22 +20,49 @@ pub struct Args { #[clap(flatten)] pub config: ConfigCli, + + #[arg(long, short, conflicts_with = "environments")] + pub all: bool, } pub async fn execute(args: Args) -> miette::Result<()> { let project = Project::load_or_else_discover(args.manifest_path.as_deref())?.with_cli_config(args.config); - if let Some(envs) = args.environments { - for env in envs { - let environment = project.environment_from_name_or_env_var(Some(env))?; - get_up_to_date_prefix(&environment, args.lock_file_usage.into(), false).await?; - } + // Install either: + // + // 1. specific environments + // 2. all environments + // 3. default environment (if no environments are specified) + let envs = if let Some(envs) = args.environments { + envs + } else if args.all { + project + .environments() + .iter() + .map(|env| env.name().to_string()) + .collect() } else { - let environment = project.environment_from_name_or_env_var(None)?; + vec![project.default_environment().name().to_string()] + }; + + let mut installed_envs = Vec::with_capacity(envs.len()); + for env in envs { + let environment = project.environment_from_name_or_env_var(Some(env))?; + installed_envs.push(environment.name().to_string()); get_up_to_date_prefix(&environment, args.lock_file_usage.into(), false).await?; } + let s = if installed_envs.len() > 1 { "s" } else { "" }; + // Message what's installed + eprintln!( + "> Installed environment{s}: {}!", + installed_envs + .iter() + .map(|n| console::style(n).bold()) + .join(", "), + ); + // Emit success eprintln!( "{}Project in {} is ready to use!", From c237d778bb1816c1ae14cd28b8c7e8486aa2398d Mon Sep 17 00:00:00 2001 From: Tim de Jager Date: Sun, 19 May 2024 12:37:44 -0400 Subject: [PATCH 04/11] fix: fix test --- tests/common/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 56a16932c..a1994e7a6 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -370,6 +370,7 @@ impl PixiControl { locked: false, }, config: Default::default(), + all: false, }, } } From cdd40b31714fe9aeb71bf121d4f5e4bcc4b81ee4 Mon Sep 17 00:00:00 2001 From: Tim de Jager Date: Mon, 20 May 2024 06:42:12 -0400 Subject: [PATCH 05/11] Update src/cli/install.rs Co-authored-by: Ruben Arts --- src/cli/install.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/install.rs b/src/cli/install.rs index e871b2c2a..29a0e6b0a 100644 --- a/src/cli/install.rs +++ b/src/cli/install.rs @@ -56,7 +56,7 @@ pub async fn execute(args: Args) -> miette::Result<()> { let s = if installed_envs.len() > 1 { "s" } else { "" }; // Message what's installed eprintln!( - "> Installed environment{s}: {}!", + "> The following environment{s} are ready to use: \n\t{}", installed_envs .iter() .map(|n| console::style(n).bold()) From 442997a69b0034bf213cb1ba8540b79d477878a6 Mon Sep 17 00:00:00 2001 From: Tim de Jager Date: Mon, 20 May 2024 06:42:53 -0400 Subject: [PATCH 06/11] fix: small changes --- src/cli/install.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cli/install.rs b/src/cli/install.rs index 29a0e6b0a..3d21199c4 100644 --- a/src/cli/install.rs +++ b/src/cli/install.rs @@ -16,7 +16,7 @@ pub struct Args { pub lock_file_usage: super::LockFileUsageArgs, #[arg(long, short)] - pub environments: Option>, + pub environment: Option>, #[clap(flatten)] pub config: ConfigCli, @@ -34,7 +34,7 @@ pub async fn execute(args: Args) -> miette::Result<()> { // 1. specific environments // 2. all environments // 3. default environment (if no environments are specified) - let envs = if let Some(envs) = args.environments { + let envs = if let Some(envs) = args.environment { envs } else if args.all { project From 9c388a0c92acc02afaf68e0064b1c39119a518ba Mon Sep 17 00:00:00 2001 From: Tim de Jager Date: Mon, 20 May 2024 11:52:32 -0400 Subject: [PATCH 07/11] fix: small fixes --- src/cli/install.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/cli/install.rs b/src/cli/install.rs index 3d21199c4..3eb861f17 100644 --- a/src/cli/install.rs +++ b/src/cli/install.rs @@ -49,18 +49,15 @@ pub async fn execute(args: Args) -> miette::Result<()> { let mut installed_envs = Vec::with_capacity(envs.len()); for env in envs { let environment = project.environment_from_name_or_env_var(Some(env))?; - installed_envs.push(environment.name().to_string()); get_up_to_date_prefix(&environment, args.lock_file_usage.into(), false).await?; + installed_envs.push(environment.name().clone()); } let s = if installed_envs.len() > 1 { "s" } else { "" }; // Message what's installed eprintln!( "> The following environment{s} are ready to use: \n\t{}", - installed_envs - .iter() - .map(|n| console::style(n).bold()) - .join(", "), + installed_envs.iter().map(|n| n.fancy_display()).join(", "), ); // Emit success From e84e7892285e5f99bcf5af4713359d534f45ee36 Mon Sep 17 00:00:00 2001 From: Ruben Arts Date: Tue, 21 May 2024 09:49:55 +0200 Subject: [PATCH 08/11] fix: rename to environment --- src/cli/install.rs | 2 +- tests/common/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cli/install.rs b/src/cli/install.rs index 3eb861f17..c8c29ff83 100644 --- a/src/cli/install.rs +++ b/src/cli/install.rs @@ -21,7 +21,7 @@ pub struct Args { #[clap(flatten)] pub config: ConfigCli, - #[arg(long, short, conflicts_with = "environments")] + #[arg(long, short, conflicts_with = "environment")] pub all: bool, } diff --git a/tests/common/mod.rs b/tests/common/mod.rs index a1994e7a6..72608b734 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -363,7 +363,7 @@ impl PixiControl { pub fn install(&self) -> InstallBuilder { InstallBuilder { args: Args { - environments: None, + environment: None, manifest_path: Some(self.manifest_path()), lock_file_usage: LockFileUsageArgs { frozen: false, From 6eacd191414821955119a1b485986655f18b2cf5 Mon Sep 17 00:00:00 2001 From: Ruben Arts Date: Tue, 21 May 2024 11:25:26 +0200 Subject: [PATCH 09/11] misc: improve final message looks --- src/cli/install.rs | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/cli/install.rs b/src/cli/install.rs index c8c29ff83..88ca63dd4 100644 --- a/src/cli/install.rs +++ b/src/cli/install.rs @@ -53,19 +53,24 @@ pub async fn execute(args: Args) -> miette::Result<()> { installed_envs.push(environment.name().clone()); } - let s = if installed_envs.len() > 1 { "s" } else { "" }; // Message what's installed - eprintln!( - "> The following environment{s} are ready to use: \n\t{}", - installed_envs.iter().map(|n| n.fancy_display()).join(", "), - ); + if installed_envs.len() == 1 { + eprintln!( + "{}The {} environment is installed.", + console::style(console::Emoji("✔ ", "")).green(), + installed_envs[0].fancy_display(), + ); + } else { + eprintln!( + "{}The following environments where installed: \n\t{}", + console::style(console::Emoji("✔ ", "")).green(), + installed_envs + .iter() + .map(|n| n.fancy_display()) + .join("\n\t"), + ); + } - // Emit success - eprintln!( - "{}Project in {} is ready to use!", - console::style(console::Emoji("✔ ", "")).green(), - project.root().display() - ); Project::warn_on_discovered_from_env(args.manifest_path.as_deref()); Ok(()) } From f35fbe8ae4b674a38b2c5b446e4e808d53ef174e Mon Sep 17 00:00:00 2001 From: Ruben Arts Date: Tue, 21 May 2024 14:00:03 +0200 Subject: [PATCH 10/11] Update src/cli/install.rs Co-authored-by: Olivier Lacroix --- src/cli/install.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/install.rs b/src/cli/install.rs index 88ca63dd4..4d9156506 100644 --- a/src/cli/install.rs +++ b/src/cli/install.rs @@ -62,7 +62,7 @@ pub async fn execute(args: Args) -> miette::Result<()> { ); } else { eprintln!( - "{}The following environments where installed: \n\t{}", + "{}The following environments have been installed: \n\t{}", console::style(console::Emoji("✔ ", "")).green(), installed_envs .iter() From 832aac668ffb7cba09e7c86b6ca13fcdbd3964e2 Mon Sep 17 00:00:00 2001 From: Ruben Arts Date: Tue, 21 May 2024 14:00:10 +0200 Subject: [PATCH 11/11] Update src/cli/install.rs Co-authored-by: Olivier Lacroix --- src/cli/install.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/install.rs b/src/cli/install.rs index 4d9156506..7f854c6ae 100644 --- a/src/cli/install.rs +++ b/src/cli/install.rs @@ -56,7 +56,7 @@ pub async fn execute(args: Args) -> miette::Result<()> { // Message what's installed if installed_envs.len() == 1 { eprintln!( - "{}The {} environment is installed.", + "{}The {} environment has been installed.", console::style(console::Emoji("✔ ", "")).green(), installed_envs[0].fancy_display(), );