select.rs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. extern crate clap;
  2. extern crate rrecutils;
  3. fn main() {
  4. let matches = clap::App::new("rr-sel")
  5. .version("0.0")
  6. .author("Getty Ritter <rrecutils@infinitenegativeutility.com>")
  7. .about("Print records from a recfile")
  8. .arg(clap::Arg::with_name("type")
  9. .long("type")
  10. .short("t")
  11. .required(false)
  12. .takes_value(true))
  13. .arg(clap::Arg::with_name("include-descriptors")
  14. .long("include-descriptors")
  15. .short("d")
  16. .required(false)
  17. .takes_value(false))
  18. .arg(clap::Arg::with_name("collapse")
  19. .long("collapse")
  20. .short("C")
  21. .required(false)
  22. .takes_value(false))
  23. .arg(clap::Arg::with_name("sort")
  24. .long("sort")
  25. .short("S")
  26. .required(false)
  27. .takes_value(true))
  28. .arg(clap::Arg::with_name("group-by")
  29. .long("group-by")
  30. .short("G")
  31. .required(false)
  32. .takes_value(true))
  33. .get_matches();
  34. let source = std::io::stdin();
  35. let mut records = rrecutils::Recfile::parse(source.lock()).unwrap();
  36. if let Some(typ) = matches.value_of("type") {
  37. records.filter_by_type(typ);
  38. }
  39. records.write(&mut std::io::stdout());
  40. }