From af2bc1f286a831e61881b9f2bb49ebd8b0fca682 Mon Sep 17 00:00:00 2001 From: Ruben Arts Date: Tue, 15 Oct 2024 10:46:36 +0200 Subject: [PATCH 1/2] fix: parse env name on adding --- src/cli/project/environment/add.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cli/project/environment/add.rs b/src/cli/project/environment/add.rs index 8d81ba335..169b02e68 100644 --- a/src/cli/project/environment/add.rs +++ b/src/cli/project/environment/add.rs @@ -1,6 +1,7 @@ use crate::Project; use clap::Parser; use pixi_manifest::EnvironmentName; +use std::str::FromStr; #[derive(Parser, Debug)] pub struct Args { @@ -26,7 +27,7 @@ pub struct Args { pub async fn execute(mut project: Project, args: Args) -> miette::Result<()> { let environment_exists = project - .environment(&EnvironmentName::Named(args.name.clone())) + .environment(&EnvironmentName::from_str(args.name.as_str())?) .is_some(); if environment_exists && !args.force { return Err(miette::miette!( From 4b38697c8ccf5a51c3925f36f288e458f8490bc1 Mon Sep 17 00:00:00 2001 From: Julian Hofer Date: Tue, 15 Oct 2024 16:09:04 +0200 Subject: [PATCH 2/2] Use EnvironmentName directly in clap --- src/cli/project/environment/add.rs | 9 +++------ tests/common/mod.rs | 4 ++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/cli/project/environment/add.rs b/src/cli/project/environment/add.rs index 169b02e68..67b8957fc 100644 --- a/src/cli/project/environment/add.rs +++ b/src/cli/project/environment/add.rs @@ -1,12 +1,11 @@ use crate::Project; use clap::Parser; use pixi_manifest::EnvironmentName; -use std::str::FromStr; #[derive(Parser, Debug)] pub struct Args { /// The name of the environment to add. - pub name: String, + pub name: EnvironmentName, /// Features to add to the environment. #[arg(short, long = "feature")] @@ -26,9 +25,7 @@ pub struct Args { } pub async fn execute(mut project: Project, args: Args) -> miette::Result<()> { - let environment_exists = project - .environment(&EnvironmentName::from_str(args.name.as_str())?) - .is_some(); + let environment_exists = project.environment(&args.name).is_some(); if environment_exists && !args.force { return Err(miette::miette!( help = "use --force to overwrite the existing environment", @@ -39,7 +36,7 @@ pub async fn execute(mut project: Project, args: Args) -> miette::Result<()> { // Add the platforms to the lock-file project.manifest.add_environment( - args.name.clone(), + args.name.as_str().to_string(), args.features, args.solve_group, args.no_default_feature, diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 08d310936..c4b1e5486 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -352,11 +352,11 @@ impl PixiControl { } } - pub fn project_environment_add(&self, name: &str) -> ProjectEnvironmentAddBuilder { + pub fn project_environment_add(&self, name: EnvironmentName) -> ProjectEnvironmentAddBuilder { ProjectEnvironmentAddBuilder { manifest_path: Some(self.manifest_path()), args: project::environment::add::Args { - name: name.to_string(), + name, features: None, solve_group: None, no_default_feature: false,