Skip to content

Commit

Permalink
feat: allow installing multiple envs at once (prefix-dev#1413)
Browse files Browse the repository at this point in the history
Co-authored-by: Ruben Arts <[email protected]>
Co-authored-by: Ruben Arts <[email protected]>
Co-authored-by: Olivier Lacroix <[email protected]>
  • Loading branch information
4 people authored May 22, 2024
1 parent f7dd008 commit 3a7c3ee
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
55 changes: 46 additions & 9 deletions src/cli/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,25 +17,61 @@ pub struct Args {

/// The environment to install
#[arg(long, short)]
pub environment: Option<String>,
pub environment: Option<Vec<String>>,

#[clap(flatten)]
pub config: ConfigCli,

#[arg(long, short, conflicts_with = "environment")]
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);
let environment = project.environment_from_name_or_env_var(args.environment)?;

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.environment {
envs
} else if args.all {
project
.environments()
.iter()
.map(|env| env.name().to_string())
.collect()
} else {
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))?;
get_up_to_date_prefix(&environment, args.lock_file_usage.into(), false).await?;
installed_envs.push(environment.name().clone());
}

// Message what's installed
if installed_envs.len() == 1 {
eprintln!(
"{}The {} environment has been installed.",
console::style(console::Emoji("✔ ", "")).green(),
installed_envs[0].fancy_display(),
);
} else {
eprintln!(
"{}The following environments have been 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(())
}
1 change: 1 addition & 0 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ impl PixiControl {
locked: false,
},
config: Default::default(),
all: false,
},
}
}
Expand Down

0 comments on commit 3a7c3ee

Please sign in to comment.