From a54ff535e56f75eb8c0e0c3f057567c1a882ccdb Mon Sep 17 00:00:00 2001 From: Tim de Jager Date: Thu, 30 May 2024 11:43:08 +0200 Subject: [PATCH 1/2] fix: should now use the activated environment when running a task --- src/cli/run.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/cli/run.rs b/src/cli/run.rs index 718492379..05a9b302a 100644 --- a/src/cli/run.rs +++ b/src/cli/run.rs @@ -1,7 +1,6 @@ use std::collections::hash_map::Entry; use std::collections::HashSet; use std::convert::identity; -use std::str::FromStr; use std::{collections::HashMap, path::PathBuf, string::String}; use crate::config::ConfigCli; @@ -63,16 +62,18 @@ pub async fn execute(args: Args) -> miette::Result<()> { verify_prefix_location_unchanged(project.default_environment().dir().as_path()).await?; // Extract the passed in environment name. - let explicit_environment = args - .environment - .map(|n| EnvironmentName::from_str(n.as_str())) - .transpose()? - .map(|n| { + let env_name = EnvironmentName::from_arg_or_env_var(args.environment).into_diagnostic()?; + // Find the environment to run the task in, if any were specified. + let explicit_environment = if env_name.is_default() { + None + } else { + Some( project - .environment(&n) - .ok_or_else(|| miette::miette!("unknown environment '{n}'")) - }) - .transpose()?; + .environment(&env_name) + // Error out if the environment is not found. + .ok_or_else(|| miette!("unknown environment '{env_name}'"))?, + ) + }; // Verify that the current platform has the required virtual packages for the environment. if let Some(ref explicit_environment) = explicit_environment { From 0765e5674dd0a04cc68ed356e48678ad8a7a7e37 Mon Sep 17 00:00:00 2001 From: Tim de Jager Date: Thu, 30 May 2024 14:27:42 +0200 Subject: [PATCH 2/2] fix: fix by using project function for getting env --- src/cli/run.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/cli/run.rs b/src/cli/run.rs index 05a9b302a..d504c0c1a 100644 --- a/src/cli/run.rs +++ b/src/cli/run.rs @@ -22,7 +22,6 @@ use crate::Project; use crate::lock_file::LockFileDerivedData; use crate::lock_file::UpdateLockFileOptions; use crate::progress::await_in_progress; -use crate::project::manifest::EnvironmentName; use crate::project::virtual_packages::verify_current_platform_has_required_virtual_packages; use crate::project::Environment; use thiserror::Error; @@ -62,17 +61,12 @@ pub async fn execute(args: Args) -> miette::Result<()> { verify_prefix_location_unchanged(project.default_environment().dir().as_path()).await?; // Extract the passed in environment name. - let env_name = EnvironmentName::from_arg_or_env_var(args.environment).into_diagnostic()?; + let environment = project.environment_from_name_or_env_var(args.environment.clone())?; // Find the environment to run the task in, if any were specified. - let explicit_environment = if env_name.is_default() { + let explicit_environment = if environment.is_default() { None } else { - Some( - project - .environment(&env_name) - // Error out if the environment is not found. - .ok_or_else(|| miette!("unknown environment '{env_name}'"))?, - ) + Some(environment) }; // Verify that the current platform has the required virtual packages for the environment.