Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow installing multiple envs at once #1413

Merged
merged 14 commits into from
May 22, 2024
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
Loading