Skip to content

Commit

Permalink
wip: change highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
baszalmstra committed May 23, 2024
1 parent c1e31da commit 18e2477
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 16 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ serde_json = "1.0.116"
serde_with = { version = "3.7.0", features = ["indexmap"] }
serde_yaml = "0.9.34"
shlex = "1.3.0"
similar = { version = "2.5.0", features = ["inline"] }
spdx = "0.10.4"
strsim = "0.11.1"
tabwriter = { version = "1.4.0", features = ["ansi_formatting"] }
Expand Down
1 change: 0 additions & 1 deletion src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ pub enum Command {
Remove(remove::Args),
#[clap(visible_alias = "i")]
Install(install::Args),
#[clap(visible_alias = "u")]
Update(update::Args),

// Execution commands
Expand Down
77 changes: 62 additions & 15 deletions src/cli/update.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
use std::{cmp::Ordering, collections::HashSet, path::PathBuf};
use std::{
cmp::Ordering,
collections::HashSet,
io::{stdout, Write},
path::PathBuf,
};

use ahash::HashMap;
use clap::Parser;
use console::Style;
use indexmap::IndexMap;
use itertools::{Either, Itertools};
use miette::MietteDiagnostic;
use rattler_conda_types::Platform;
use rattler_lock::{LockFile, LockFileBuilder, Package};
use similar::{Algorithm, ChangeTag};
use tabwriter::TabWriter;

use crate::{
config::ConfigCli, consts, load_lock_file, lock_file::UpdateContext, EnvironmentName, Project,
Expand Down Expand Up @@ -140,7 +148,7 @@ pub async fn execute(args: Args) -> miette::Result<()> {
let diff = LockFileDiff::from_lock_files(&loaded_lock_file, &updated_lock_file.lock_file);
if diff.is_empty() {
println!(
"{}Lock-file is up-to-date",
"{}Lock-file was already up-to-date",
console::style(console::Emoji("✔ ", "")).green()
);
} else {
Expand Down Expand Up @@ -423,15 +431,22 @@ impl LockFileDiff {
}
}

let mut writer = TabWriter::new(stdout());
for (environment_name, environment) in
self.environment.iter().sorted_by(|(a, _), (b, _)| a.cmp(b))
{
println!(
"Environment: {}",
writeln!(

Check failure on line 438 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Cargo Lint

unused `std::result::Result` that must be used

Check failure on line 438 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Linux-x86_64

unused `Result` that must be used

Check failure on line 438 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | macOS-x86

unused `Result` that must be used

Check failure on line 438 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | macOS-arm

unused `Result` that must be used

Check failure on line 438 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Linux-aarch64

unused `Result` that must be used

Check failure on line 438 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Windows

unused `Result` that must be used

Check failure on line 438 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Windows-arm

unused `Result` that must be used
writer,
"Environment: {}\t\t",
consts::ENVIRONMENT_STYLE.apply_to(environment_name),
);
for (platform, packages) in environment {
println!(" Platform: {}", consts::PLATFORM_STYLE.apply_to(platform));
writeln!(

Check failure on line 444 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Cargo Lint

unused `std::result::Result` that must be used

Check failure on line 444 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Linux-x86_64

unused `Result` that must be used

Check failure on line 444 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | macOS-x86

unused `Result` that must be used

Check failure on line 444 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | macOS-arm

unused `Result` that must be used

Check failure on line 444 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Linux-aarch64

unused `Result` that must be used

Check failure on line 444 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Windows

unused `Result` that must be used

Check failure on line 444 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Windows-arm

unused `Result` that must be used
writer,
" Platform: {}\t\t",
consts::PLATFORM_STYLE.apply_to(platform)
);

itertools::chain!(
packages.added.iter().map(Change::Added),
packages.removed.iter().map(Change::Removed),
Expand All @@ -444,32 +459,64 @@ impl LockFileDiff {
})
.for_each(|c| match c {
Change::Added(p) => {
println!(
writeln!(

Check failure on line 462 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Cargo Lint

unused `std::result::Result` that must be used

Check failure on line 462 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Linux-x86_64

unused `Result` that must be used

Check failure on line 462 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | macOS-x86

unused `Result` that must be used

Check failure on line 462 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | macOS-arm

unused `Result` that must be used

Check failure on line 462 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Linux-aarch64

unused `Result` that must be used

Check failure on line 462 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Windows

unused `Result` that must be used

Check failure on line 462 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Windows-arm

unused `Result` that must be used
writer,
" {} {} {}",
console::style("+").green(),
p.name(),
format_package_identifier(p)
)
);
}
Change::Removed(p) => {
println!(
writeln!(

Check failure on line 471 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Cargo Lint

unused `std::result::Result` that must be used

Check failure on line 471 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Linux-x86_64

unused `Result` that must be used

Check failure on line 471 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | macOS-x86

unused `Result` that must be used

Check failure on line 471 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | macOS-arm

unused `Result` that must be used

Check failure on line 471 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Linux-aarch64

unused `Result` that must be used

Check failure on line 471 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Windows

unused `Result` that must be used

Check failure on line 471 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Windows-arm

unused `Result` that must be used
writer,
" {} {} {}",
console::style("-").red(),
p.name(),
format_package_identifier(p)
)
);
}
Change::Changed(previous, current) => {
println!(
" {} {} {} -> {}",
write!(

Check failure on line 480 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Cargo Lint

unused `std::result::Result` that must be used

Check failure on line 480 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Linux-x86_64

unused `Result` that must be used

Check failure on line 480 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | macOS-x86

unused `Result` that must be used

Check failure on line 480 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | macOS-arm

unused `Result` that must be used

Check failure on line 480 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Linux-aarch64

unused `Result` that must be used

Check failure on line 480 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Windows

unused `Result` that must be used

Check failure on line 480 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Windows-arm

unused `Result` that must be used
writer,
" {} {} ",
console::style("~").yellow(),
previous.name(),
format_package_identifier(previous),
format_package_identifier(current)
)
previous.name()
);
let previous = format_package_identifier(previous);
let current = format_package_identifier(current);
let diff = similar::TextDiff::configure()
.algorithm(Algorithm::Lcs)
.diff_lines(&previous, &current);
for op in diff.ops().iter() {
for (idx, change) in diff.iter_inline_changes(op).enumerate() {
let s = match change.tag() {
ChangeTag::Delete => Style::new().bold(),
ChangeTag::Insert => Style::new().bold(),
ChangeTag::Equal => Style::new().dim(),
};
for (emphasized, value) in change.iter_strings_lossy() {
if emphasized {
write!(

Check failure on line 500 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Cargo Lint

unused `std::result::Result` that must be used

Check failure on line 500 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Linux-x86_64

unused `Result` that must be used

Check failure on line 500 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | macOS-x86

unused `Result` that must be used

Check failure on line 500 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | macOS-arm

unused `Result` that must be used

Check failure on line 500 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Linux-aarch64

unused `Result` that must be used

Check failure on line 500 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Windows

unused `Result` that must be used

Check failure on line 500 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Windows-arm

unused `Result` that must be used
writer,
"{}",
s.apply_to(value).underlined().on_black()
);
} else {
write!(writer, "{}", value);

Check failure on line 506 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Cargo Lint

unused `std::result::Result` that must be used

Check failure on line 506 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Linux-x86_64

unused `Result` that must be used

Check failure on line 506 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | macOS-x86

unused `Result` that must be used

Check failure on line 506 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | macOS-arm

unused `Result` that must be used

Check failure on line 506 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Linux-aarch64

unused `Result` that must be used

Check failure on line 506 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Windows

unused `Result` that must be used

Check failure on line 506 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Windows-arm

unused `Result` that must be used
}
}
if idx == 0 {
write!(writer, "\t->\t");

Check failure on line 510 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Cargo Lint

unused `std::result::Result` that must be used

Check failure on line 510 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Linux-x86_64

unused `Result` that must be used

Check failure on line 510 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | macOS-x86

unused `Result` that must be used

Check failure on line 510 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | macOS-arm

unused `Result` that must be used

Check failure on line 510 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Linux-aarch64

unused `Result` that must be used

Check failure on line 510 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Windows

unused `Result` that must be used

Check failure on line 510 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Windows-arm

unused `Result` that must be used
}
}
}

writeln!(writer);

Check failure on line 515 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Cargo Lint

unused `std::result::Result` that must be used

Check failure on line 515 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Linux-x86_64

unused `Result` that must be used

Check failure on line 515 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | macOS-x86

unused `Result` that must be used

Check failure on line 515 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | macOS-arm

unused `Result` that must be used

Check failure on line 515 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Linux-aarch64

unused `Result` that must be used

Check failure on line 515 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Windows

unused `Result` that must be used

Check failure on line 515 in src/cli/update.rs

View workflow job for this annotation

GitHub Actions / Build Binary | Windows-arm

unused `Result` that must be used
}
});
}
}
writer.flush().unwrap();
}
}

0 comments on commit 18e2477

Please sign in to comment.