this repo has no description

feat: use paths so we can check if they exist first

+19 -10
+19 -10
src/main.rs
··· 1 - use std::env; 1 + use std::{env, path::PathBuf}; 2 2 3 3 use argh::FromArgs; 4 4 use color_eyre::Result; ··· 21 21 22 22 /// the generation we are switching from 23 23 #[argh(positional)] 24 - before: String, 24 + before: PathBuf, 25 25 26 26 /// the generation we are switching to 27 - #[argh(positional, default = "String::from(\"/run/current-system/\")")] 28 - after: String, 27 + #[argh(positional, default = "PathBuf::from(\"/run/current-system/\")")] 28 + after: PathBuf, 29 29 } 30 30 31 31 fn main() -> Result<()> { ··· 42 42 } 43 43 } 44 44 45 - // Check if the generations are valid 46 - if before.is_empty() || after.is_empty() { 47 - eprintln!("Both generations must be specified."); 45 + if !before.exists() { 46 + eprintln!("Before generation does not exist: {}", before.display()); 47 + std::process::exit(1); 48 + } 49 + 50 + if !after.exists() { 51 + eprintln!("After generation does not exist: {}", after.display()); 48 52 std::process::exit(1); 49 53 } 50 54 51 - let packages: PackageListDiff = DiffRoot::new(&before, &after)?.into(); 55 + let before_str = before 56 + .to_str() 57 + .expect("could not convert before path to str"); 58 + let after_str = after.to_str().expect("could not convert after path to str"); 59 + 60 + let packages: PackageListDiff = DiffRoot::new(before_str, after_str)?.into(); 52 61 53 62 let arrow_style = Style::new().bold().fg(Color::LightGray); 54 63 55 - let before_text = format!("<<< {before}"); 56 - let after_text = format!(">>> {after}"); 64 + let before_text = format!("<<< {before_str}"); 65 + let after_text = format!(">>> {after_str}"); 57 66 58 67 println!("{}", arrow_style.paint(before_text)); 59 68 println!("{}\n", arrow_style.paint(after_text));