app

Local-first trade for farms and co-ops
git clone https://radroots.dev/git/app.git
Log | Files | Refs | README | LICENSE

main.rs (2917B)


      1 use harvestcircle_xtask::{Command, run};
      2 use std::env;
      3 use std::process::ExitCode;
      4 
      5 fn main() -> ExitCode {
      6     let mut arguments = env::args().skip(1);
      7     let Some(command) = arguments.next() else {
      8         eprintln!(
      9             "usage: cargo run --manifest-path tools/xtask/Cargo.toml -- <design-source-audit|repo-audit|namespace-audit|provenance-check|qualification-report>"
     10         );
     11         return ExitCode::FAILURE;
     12     };
     13     if command == "affected-report" {
     14         let mut base = env::var("HARVESTCIRCLE_AFFECTED_BASE")
     15             .ok()
     16             .filter(|v| !v.is_empty());
     17         let mut head = "HEAD".to_owned();
     18         let mut seen_head = false;
     19         let mut seen_base = false;
     20         while let Some(flag) = arguments.next() {
     21             let Some(value) = arguments.next() else {
     22                 eprintln!("affected-report requires --base <commit> and optional --head <commit>");
     23                 return ExitCode::FAILURE;
     24             };
     25             match flag.as_str() {
     26                 "--base" if !seen_base => {
     27                     base = Some(value);
     28                     seen_base = true;
     29                 }
     30                 "--head" if !seen_head => {
     31                     head = value;
     32                     seen_head = true;
     33                 }
     34                 _ => {
     35                     eprintln!("unknown or repeated affected-report option");
     36                     return ExitCode::FAILURE;
     37                 }
     38             }
     39         }
     40         let result = env::current_dir()
     41             .map_err(|e| e.to_string())
     42             .and_then(|root| harvestcircle_xtask::affected::report(&root, base.as_deref(), &head));
     43         return match result {
     44             Ok((report, green)) => {
     45                 print!("{report}");
     46                 if green {
     47                     ExitCode::SUCCESS
     48                 } else {
     49                     ExitCode::FAILURE
     50                 }
     51             }
     52             Err(message) => {
     53                 eprintln!("{message}");
     54                 ExitCode::FAILURE
     55             }
     56         };
     57     }
     58     if arguments.next().is_some() {
     59         eprintln!("xtask commands do not accept positional arguments");
     60         return ExitCode::FAILURE;
     61     }
     62     let command = match command.parse::<Command>() {
     63         Ok(command) => command,
     64         Err(message) => {
     65             eprintln!("{message}");
     66             return ExitCode::FAILURE;
     67         }
     68     };
     69     let root = match env::current_dir() {
     70         Ok(root) => root,
     71         Err(error) => {
     72             eprintln!("unable to resolve the HarvestCircle repository root: {error}");
     73             return ExitCode::FAILURE;
     74         }
     75     };
     76     match run(&root, command) {
     77         Ok(report) => {
     78             print!("{report}");
     79             ExitCode::SUCCESS
     80         }
     81         Err(findings) => {
     82             for finding in findings {
     83                 eprintln!("{finding}");
     84             }
     85             ExitCode::FAILURE
     86         }
     87     }
     88 }