this repo has no description
1use std::path::PathBuf;
2
3use clap::Parser;
4use color_eyre::Result;
5use diff::PackageListDiff;
6use nu_ansi_term::{Color, Style};
7use terminal_light::luma;
8
9mod color;
10mod diff;
11mod package;
12mod parser;
13mod versioning;
14
15use self::parser::DiffRoot;
16
17#[derive(Parser, PartialEq, Debug)]
18/// List the package differences between two `NixOS` generations
19struct Args {
20 /// the path to the lix bin directory
21 #[arg(short, long)]
22 lix_bin: Option<PathBuf>,
23
24 /// the generation we are switching from
25 before: PathBuf,
26
27 /// the generation we are switching to
28 #[arg(default_value = "/run/current-system/")]
29 after: PathBuf,
30
31 /// sort by size difference
32 #[arg(short, long)]
33 size: bool,
34
35 /// disable colored output (also respects NO_COLOR env var and CI environments)
36 #[arg(long)]
37 no_color: bool,
38}
39
40fn main() -> Result<()> {
41 let args = Args::parse();
42
43 // Initialize color configuration
44 color::init(args.no_color);
45
46 let before = args.before;
47 let after = args.after;
48 let lix_bin = args.lix_bin;
49
50 let mut lix_exe = None;
51 if let Some(lix_bin) = lix_bin {
52 lix_exe = if lix_bin.is_dir() {
53 Some(lix_bin.join("nix"))
54 } else {
55 Some(lix_bin)
56 }
57 }
58
59 if !before.exists() {
60 eprintln!("Before generation does not exist: {}", before.display());
61 std::process::exit(1);
62 }
63
64 if !after.exists() {
65 eprintln!("After generation does not exist: {}", after.display());
66 std::process::exit(1);
67 }
68
69 let packages_diff = DiffRoot::new(lix_exe, &before, &after)?;
70 let mut packages: PackageListDiff = PackageListDiff::new();
71 packages.by_size = args.size;
72 packages.from_diff_root(packages_diff);
73
74 let before_text = format!("<<< {}", before.display());
75 let after_text = format!(">>> {}", after.display());
76
77 if color::color_enabled() {
78 let text_color = if luma().is_ok_and(|luma| luma > 0.6) {
79 Color::DarkGray
80 } else {
81 Color::LightGray
82 };
83 let arrow_style = Style::new().bold().fg(text_color);
84 println!("{}", arrow_style.paint(&before_text));
85 println!("{}\n", arrow_style.paint(&after_text));
86 } else {
87 println!("{before_text}");
88 println!("{after_text}\n");
89 }
90
91 println!("{packages}");
92
93 Ok(())
94}