main.rs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. use clap::{Parser, Subcommand};
  2. use clap_verbosity_flag::{InfoLevel, Verbosity};
  3. use std::process::ExitCode;
  4. #[macro_use]
  5. mod utils;
  6. mod bench;
  7. mod logger;
  8. mod prototyper;
  9. mod test;
  10. #[macro_use]
  11. extern crate log;
  12. use crate::bench::BenchArg;
  13. use crate::prototyper::PrototyperArg;
  14. use crate::test::TestArg;
  15. #[derive(Parser)]
  16. #[clap(
  17. name = "xtask",
  18. about = "A task runner for building, running and testing Prototyper",
  19. long_about = None,
  20. )]
  21. struct Cli {
  22. #[clap(subcommand)]
  23. cmd: Cmd,
  24. #[command(flatten)]
  25. verbose: Verbosity<InfoLevel>,
  26. }
  27. #[derive(Subcommand)]
  28. enum Cmd {
  29. Prototyper(PrototyperArg),
  30. Test(TestArg),
  31. Bench(BenchArg),
  32. }
  33. fn main() -> ExitCode {
  34. let cli_args = Cli::parse();
  35. logger::Logger::init(&cli_args).expect("Unable to init logger");
  36. if let Some(code) = match cli_args.cmd {
  37. Cmd::Prototyper(ref arg) => prototyper::run(arg),
  38. Cmd::Test(ref arg) => test::run(arg),
  39. Cmd::Bench(ref arg) => bench::run(arg),
  40. } {
  41. if code.success() {
  42. info!("Finished");
  43. return ExitCode::SUCCESS;
  44. }
  45. }
  46. error!("Failed to run task!");
  47. ExitCode::FAILURE
  48. }