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: pixi diff #2340

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/cli/diff.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use std::path::PathBuf;

use clap::Parser;
use miette::IntoDiagnostic;
use pixi_config::{self, ConfigCli};
use rattler_lock::LockFile;

use crate::{
cli::update::{LockFileDiff, LockFileJsonDiff},
Project,
};

use super::cli_config::ProjectConfig;

#[derive(Parser, Debug, Default)]
pub struct Args {
#[clap(flatten)]
pub config: ConfigCli,

#[clap(flatten)]
pub project_config: ProjectConfig,

#[arg(long)]
pub old_lockfile: PathBuf,
}

pub async fn execute(args: Args) -> miette::Result<()> {
let project = Project::load_or_else_discover(args.project_config.manifest_path.as_deref())?
.with_cli_config(args.config);
let current_lockfile = LockFile::from_path(&project.lock_file_path()).into_diagnostic()?;

let input: Box<dyn std::io::Read + 'static> = if args.old_lockfile.as_os_str() == "-" {
Box::new(std::io::stdin())
} else {
Box::new(std::fs::File::open(&args.old_lockfile).into_diagnostic()?)
};

let prior_lockfile = LockFile::from_reader(input).into_diagnostic()?;

let diff = LockFileDiff::from_lock_files(&prior_lockfile, &current_lockfile);
let json_diff = LockFileJsonDiff::new(&project, diff);
let json = serde_json::to_string_pretty(&json_diff).expect("failed to convert to json");
println!("{}", json);

Ok(())
}
3 changes: 3 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub mod clean;
pub mod cli_config;
pub mod completion;
pub mod config;
pub mod diff;
mod exec;
pub mod global;
pub mod has_specs;
Expand Down Expand Up @@ -104,6 +105,7 @@ pub enum Command {
#[clap(visible_alias = "s")]
Shell(shell::Args),
ShellHook(shell_hook::Args),
Diff(diff::Args),

// Project modification commands
Project(project::Args),
Expand Down Expand Up @@ -281,6 +283,7 @@ pub async fn execute_command(command: Command) -> miette::Result<()> {
Command::Tree(cmd) => tree::execute(cmd).await,
Command::Update(cmd) => update::execute(cmd).await,
Command::Exec(args) => exec::execute(args).await,
Command::Diff(args) => diff::execute(args).await,
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/cli/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ pub struct LockFileJsonDiff {
}

impl LockFileJsonDiff {
fn new(project: &Project, value: LockFileDiff) -> Self {
pub fn new(project: &Project, value: LockFileDiff) -> Self {
let mut environment = IndexMap::new();

for (environment_name, environment_diff) in value.environment {
Expand Down
Loading