select.rs 1.3 KB

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