main.rs 3.0 KB

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