Skip to content
17 changes: 8 additions & 9 deletions crates/rattler-bin/src/commands/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,13 @@ pub struct Opt {
timeout: Option<u64>,

/// Target prefix (environment path) for package installation
#[clap(short = 'p', long = "prefix", visible_alias = "target-prefix")]
target_prefix: Option<PathBuf>,
#[clap(
short = 'p',
long = "prefix",
visible_alias = "target-prefix",
default_value = ".prefix"
)]
target_prefix: PathBuf,

#[clap(long)]
strategy: Option<SolveStrategy>,
Expand Down Expand Up @@ -125,14 +130,8 @@ impl From<SolveStrategy> for rattler_solve::SolveStrategy {
pub async fn create(opt: Opt) -> miette::Result<()> {
let channel_config =
ChannelConfig::default_with_root_dir(env::current_dir().into_diagnostic()?);
let current_dir = env::current_dir().into_diagnostic()?;
let target_prefix = opt
.target_prefix
.unwrap_or_else(|| current_dir.join(".prefix"));

// Make the target prefix absolute
let target_prefix = std::path::absolute(target_prefix).into_diagnostic()?;
println!("Target prefix: {}", target_prefix.display());
let target_prefix = std::path::absolute(opt.target_prefix).into_diagnostic()?;

// Determine the platform we're going to install for
let install_platform = if let Some(platform) = opt.platform {
Expand Down
9 changes: 5 additions & 4 deletions crates/rattler-bin/src/commands/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use rattler_conda_types::{HasArtifactIdentificationRefs, PackageName, PrefixData
#[clap(after_help = r#"Examples:
rattler list -p /path/to/environment"#)]
pub struct Opt {
/// The prefix to list
#[clap(short, long)]
prefix: Option<PathBuf>,
/// Target prefix (environment path) to list
#[clap(short = 'p', long = "prefix", visible_alias = "target-prefix")]
target_prefix: Option<PathBuf>,

/// The name (or glob) of the packages to list
name: Option<PackageName>, // maybe this could be a full MatchSpec?
Expand All @@ -21,13 +21,14 @@ pub struct Opt {
}

pub async fn list(opt: Opt) -> miette::Result<()> {
let prefix = if let Some(prefix) = opt.prefix {
let prefix = if let Some(prefix) = opt.target_prefix {
prefix
} else if let Ok(prefix) = env::var("CONDA_PREFIX") {
PathBuf::from(prefix)
} else {
miette::bail!("No environment detected or passed. Tip: Use -p PATH.")
};
let prefix = std::path::absolute(&prefix).into_diagnostic()?;

let prefix_data = PrefixData::new(&prefix).into_diagnostic()?;
let header = [[
Expand Down
22 changes: 16 additions & 6 deletions crates/rattler-bin/src/commands/menu.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{fs, path::PathBuf};
use std::path::PathBuf;

use clap::Parser;
use miette::IntoDiagnostic;
Expand All @@ -7,8 +7,13 @@ use rattler_conda_types::{menuinst::MenuMode, PackageName, Platform, PrefixRecor
/// Install menu items for an installed package.
#[derive(Debug, Parser)]
pub struct InstallOpt {
/// Target prefix to look for the package (defaults to `.prefix`)
#[clap(long, short, default_value = ".prefix")]
/// Target prefix (environment path) to look for the package
#[clap(
short = 'p',
long = "prefix",
visible_alias = "target-prefix",
default_value = ".prefix"
)]
target_prefix: PathBuf,

/// Name of the package for which to install menu items
Expand All @@ -18,8 +23,13 @@ pub struct InstallOpt {
/// Remove installed menu items for a package.
#[derive(Debug, Parser)]
pub struct RemoveOpt {
/// Target prefix to look for the package (defaults to `.prefix`)
#[clap(long, short, default_value = ".prefix")]
/// Target prefix (environment path) to look for the package
#[clap(
short = 'p',
long = "prefix",
visible_alias = "target-prefix",
default_value = ".prefix"
)]
target_prefix: PathBuf,

/// Name of the package for which to remove menu items
Expand All @@ -41,7 +51,7 @@ pub async fn install_menu(opts: InstallOpt) -> miette::Result<()> {
opts.target_prefix
)
})?;
let prefix = fs::canonicalize(&opts.target_prefix).into_diagnostic()?;
let prefix = std::path::absolute(&opts.target_prefix).into_diagnostic()?;
rattler_menuinst::install_menuitems_for_record(
&prefix,
record,
Expand Down
18 changes: 10 additions & 8 deletions crates/rattler-bin/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use std::{env, path::PathBuf};
/// Run a command in an activated conda environment.
#[derive(Debug, clap::Parser)]
pub struct Opt {
/// Target prefix (environment path) for package installation
/// Target prefix (environment path) to run the command in.
/// Defaults to the active conda environment ($`CONDA_PREFIX`), then `.prefix` in the current directory.
#[clap(short = 'p', long = "prefix", visible_alias = "target-prefix")]
target_prefix: Option<PathBuf>,

Expand All @@ -19,14 +20,15 @@ pub struct Opt {
}

pub async fn run(opt: Opt) -> miette::Result<()> {
let current_dir = env::current_dir().into_diagnostic()?;
let target_prefix = opt
.target_prefix
.unwrap_or_else(|| current_dir.join(".prefix"));

let prefix = if let Some(prefix) = opt.target_prefix {
prefix
} else if let Ok(prefix) = env::var("CONDA_PREFIX") {
PathBuf::from(prefix)
} else {
env::current_dir().into_diagnostic()?.join(".prefix")
};
// Make the target prefix absolute
let target_prefix = std::path::absolute(target_prefix).into_diagnostic()?;
println!("Target prefix: {}", target_prefix.display());
let target_prefix = std::path::absolute(prefix).into_diagnostic()?;

let shell = rattler_shell::shell::ShellEnum::from_env().unwrap_or_default();
let cwd = opt.cwd.as_deref();
Expand Down
2 changes: 1 addition & 1 deletion crates/rattler-bin/src/commands/shell_hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rattler_shell::{
/// Print the shell activation hook for a conda prefix to stdout.
#[derive(Debug, Parser)]
pub struct Opt {
/// Target prefix to generate the shell hook for
/// Target prefix (environment path) to generate the shell hook for
#[clap(
short = 'p',
long = "prefix",
Expand Down
Loading