main.rs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. use anyhow::anyhow;
  2. use clap::Parser;
  3. use dioxus_cli::*;
  4. #[cfg(feature = "plugin")]
  5. use dioxus_cli::plugin::PluginManager;
  6. use Commands::*;
  7. #[tokio::main]
  8. async fn main() -> anyhow::Result<()> {
  9. let args = Cli::parse();
  10. set_up_logging();
  11. let _dioxus_config = DioxusConfig::load()
  12. .map_err(|e| anyhow!("Failed to load `Dioxus.toml` because: {e}"))?
  13. .unwrap_or_else(|| {
  14. log::warn!("You appear to be creating a Dioxus project from scratch; we will use the default config");
  15. DioxusConfig::default()
  16. });
  17. #[cfg(feature = "plugin")]
  18. PluginManager::init(_dioxus_config.plugin)
  19. .map_err(|e| anyhow!("🚫 Plugin system initialization failed: {e}"))?;
  20. match args.action {
  21. Translate(opts) => opts
  22. .translate()
  23. .map_err(|e| anyhow!("🚫 Translation of HTML into RSX failed: {}", e)),
  24. Build(opts) => opts
  25. .build()
  26. .map_err(|e| anyhow!("🚫 Building project failed: {}", e)),
  27. Clean(opts) => opts
  28. .clean()
  29. .map_err(|e| anyhow!("🚫 Cleaning project failed: {}", e)),
  30. Serve(opts) => opts
  31. .serve()
  32. .await
  33. .map_err(|e| anyhow!("🚫 Serving project failed: {}", e)),
  34. Create(opts) => opts
  35. .create()
  36. .map_err(|e| anyhow!("🚫 Creating new project failed: {}", e)),
  37. Config(opts) => opts
  38. .config()
  39. .map_err(|e| anyhow!("🚫 Configuring new project failed: {}", e)),
  40. #[cfg(feature = "plugin")]
  41. Plugin(opts) => opts
  42. .plugin()
  43. .await
  44. .map_err(|e| anyhow!("🚫 Error with plugin: {}", e)),
  45. Autoformat(opts) => opts
  46. .autoformat()
  47. .await
  48. .map_err(|e| anyhow!("🚫 Error autoformatting RSX: {}", e)),
  49. Version(opt) => {
  50. let version = opt.version();
  51. println!("{}", version);
  52. Ok(())
  53. }
  54. }
  55. }