Skip to content

Commit

Permalink
feat: Add pixi environment as CLI argument
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelzw committed Nov 22, 2024
1 parent b632e49 commit 4ced260
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ use tracing_log::AsTrace;
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Cli {
#[arg(long)]
prefix: PathBuf,
/// The pixi environment to inject packages into.
#[arg(short, long)]
environment: Option<String>,

/// The prefix to inject packages into.
#[arg(short, long)]
prefix: Option<PathBuf>,

/// The package to inject into the environment.
#[arg(long)]
package: Vec<PathBuf>,

#[command(flatten)]
Expand All @@ -36,7 +42,18 @@ async fn main() -> Result<()> {
tracing::debug!("Starting pixi-inject CLI");
tracing::debug!("Parsed CLI options: {:?}", cli);

let target_prefix = cli.prefix;
let target_prefix = match (cli.prefix, cli.environment) {
(Some(_), Some(_)) => {
return Err(anyhow::anyhow!(
"Both --prefix and --environment cannot be provided at the same time."
));
},
(Some(prefix), None) => prefix,
(None, Some(environment)) => PathBuf::from(format!(".pixi/envs/{}", environment)),
(None, None) => PathBuf::from(".pixi/envs/default"),
};
tracing::info!("Using target prefix: {:?}", target_prefix);

let packages = cli.package;

pixi_inject::pixi_inject(target_prefix, packages).await
Expand Down

0 comments on commit 4ced260

Please sign in to comment.