/src/bin/rga-preproc.rs

https://github.com/phiresky/ripgrep-all · Rust · 38 lines · 33 code · 4 blank · 1 comment · 0 complexity · eb5f1486ff796f3cd9078a2beed3581b MD5 · raw file

  1. use rga::adapters::*;
  2. use rga::preproc::*;
  3. use rga::print_dur;
  4. use ripgrep_all as rga;
  5. use anyhow::Context;
  6. use log::debug;
  7. use std::{fs::File, time::Instant};
  8. fn main() -> anyhow::Result<()> {
  9. env_logger::init();
  10. let mut arg_arr: Vec<std::ffi::OsString> = std::env::args_os().collect();
  11. let last = arg_arr.pop().expect("No filename specified");
  12. let config = rga::config::parse_args(arg_arr, true)?;
  13. //clap::App::new("rga-preproc").arg(Arg::from_usage())
  14. let path = {
  15. let filepath = last;
  16. std::env::current_dir()?.join(&filepath)
  17. };
  18. let i = File::open(&path).context("Specified input file not found")?;
  19. let mut o = std::io::stdout();
  20. let ai = AdaptInfo {
  21. inp: Box::new(i),
  22. filepath_hint: path,
  23. is_real_file: true,
  24. line_prefix: "".to_string(),
  25. archive_recursion_depth: 0,
  26. config,
  27. };
  28. let start = Instant::now();
  29. let mut oup = rga_preproc(ai).context("during preprocessing")?;
  30. debug!("finding and starting adapter took {}", print_dur(start));
  31. std::io::copy(&mut oup, &mut o).context("copying adapter output to stdout")?;
  32. debug!("running adapter took {} total", print_dur(start));
  33. Ok(())
  34. }