-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Example: ``` pixi diff --old-lockfile <(git show HEAD~100:pixi.lock) ```
- Loading branch information
Ben Moss
committed
Oct 23, 2024
1 parent
bae4984
commit a5c5712
Showing
3 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use std::path::{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 lock = LockFile::from_path(Path::new("pixi.lock")).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 old = LockFile::from_reader(input).into_diagnostic()?; | ||
|
||
let diff = LockFileDiff::from_lock_files(&old, &lock); | ||
let config = args.config; | ||
let project = Project::load_or_else_discover(args.project_config.manifest_path.as_deref())? | ||
.with_cli_config(config); | ||
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(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters