main.rs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. mod config;
  2. mod util;
  3. use clap::{App, Arg};
  4. fn main() {
  5. std::env::set_var("RUST_LOG", "Info");
  6. env_logger::init();
  7. let matches = app().get_matches();
  8. if let Some(ref matches) = matches.subcommand_matches("pb-gen") {
  9. let rust_source = matches.value_of("rust_source").unwrap();
  10. let derive_meta = matches.value_of("derive_meta").unwrap();
  11. let flutter_package_lib = matches.value_of("flutter_package_lib").unwrap();
  12. proto::ProtoGenBuilder::new()
  13. .set_rust_source_dir(rust_source)
  14. .set_derive_meta_dir(derive_meta)
  15. .set_flutter_package_lib(flutter_package_lib)
  16. .build()
  17. .gen();
  18. }
  19. if let Some(ref matches) = matches.subcommand_matches("dart-event") {
  20. let rust_source = matches.value_of("rust_source").unwrap().to_string();
  21. let output_dir = matches.value_of("output").unwrap().to_string();
  22. let code_gen = dart_event::DartEventCodeGen {
  23. rust_source,
  24. output_dir,
  25. };
  26. code_gen.gen();
  27. }
  28. }
  29. pub fn app<'a, 'b>() -> App<'a, 'b> {
  30. let app = App::new("flowy-tool")
  31. .version("0.1")
  32. .author("nathan")
  33. .about("flowy tool")
  34. .subcommand(
  35. App::new("pb-gen")
  36. .about("Generate proto file from rust code")
  37. .arg(
  38. Arg::with_name("rust_source")
  39. .long("rust_source")
  40. .value_name("DIRECTORY")
  41. .help("Directory of the cargo workspace"),
  42. )
  43. .arg(
  44. Arg::with_name("derive_meta")
  45. .long("derive_meta")
  46. .value_name("PATH")
  47. .help("Caching information used by flowy-derive"),
  48. )
  49. .arg(
  50. Arg::with_name("flutter_package_lib")
  51. .long("flutter_package_lib")
  52. .value_name("DIRECTORY"),
  53. ),
  54. )
  55. .subcommand(
  56. App::new("dart-event")
  57. .about("Generate the codes that sending events from rust ast")
  58. .arg(
  59. Arg::with_name("rust_source")
  60. .long("rust_source")
  61. .value_name("DIRECTORY")
  62. .help("Directory of the cargo workspace"),
  63. )
  64. .arg(
  65. Arg::with_name("output")
  66. .long("output")
  67. .value_name("DIRECTORY"),
  68. ),
  69. );
  70. app
  71. }