main.rs 789 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. mod cleaning;
  2. mod tsv;
  3. mod db;
  4. mod io;
  5. mod tracking;
  6. mod commands;
  7. use anyhow::{anyhow, Result};
  8. use log::*;
  9. use structopt::StructOpt;
  10. use happylog::args::LogOpts;
  11. use commands::*;
  12. /// BookData import tools
  13. #[derive(StructOpt, Debug)]
  14. #[structopt(name="bookdata")]
  15. struct Opt {
  16. #[structopt(flatten)]
  17. logging: LogOpts
  18. }
  19. fn main() -> Result<()> {
  20. let mut app = Opt::clap();
  21. let cmds = commands();
  22. for cmd in &cmds {
  23. app = app.subcommand(cmd.app().clone());
  24. }
  25. let matches = app.get_matches();
  26. let opt = Opt::from_clap(&matches);
  27. opt.logging.init()?;
  28. let (sc_name, sc_app) = matches.subcommand();
  29. debug!("subcommand name {}", sc_name);
  30. for cmd in &cmds {
  31. if cmd.name() == sc_name {
  32. cmd.run(sc_app.ok_or(anyhow!("no options"))?)?
  33. }
  34. }
  35. Ok(())
  36. }