feat: commit code
This commit is contained in:
1 parent
062d0eab47
commit
6cce4b9f4d
5 files changed
+82
-8
No files matched your search
+4
-4
@@ -4,7 +4,7 @@ pub mod clean;
|
||||
pub mod config;
|
||||
pub mod create;
|
||||
pub mod serve;
|
||||
pub mod tool;
|
||||
pub mod plugin;
|
||||
pub mod translate;
|
||||
|
||||
use crate::{
|
||||
@@ -52,9 +52,9 @@ pub enum Commands {
|
||||
/// Dioxus config file controls.
|
||||
#[clap(subcommand)]
|
||||
Config(config::Config),
|
||||
/// Install & Manage tools for Dioxus-cli.
|
||||
#[clap(subcommand)]
|
||||
Tool(tool::Tool),
|
||||
/// Manage plugins for dioxus cli
|
||||
Plugin(plugin::Plugin),
|
||||
}
|
||||
|
||||
impl Commands {
|
||||
@@ -66,7 +66,7 @@ impl Commands {
|
||||
Commands::Create(_) => "create",
|
||||
Commands::Clean(_) => "clean",
|
||||
Commands::Config(_) => "config",
|
||||
Commands::Tool(_) => "tool",
|
||||
Commands::Plugin(_) => "plugin",
|
||||
}.to_string()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
use crate::tools;
|
||||
|
||||
use super::*;
|
||||
|
||||
/// Build the Rust WASM app and all of its assets.
|
||||
#[derive(Clone, Debug, Deserialize, Subcommand)]
|
||||
#[clap(name = "plugin")]
|
||||
pub enum Plugin {
|
||||
/// Return all dioxus-cli support tools.
|
||||
List {},
|
||||
/// Get default app install path.
|
||||
AppPath {},
|
||||
/// Install a new tool.
|
||||
Add { name: String },
|
||||
}
|
||||
|
||||
impl Plugin {
|
||||
pub async fn plugin(self) -> Result<()> {
|
||||
match self {
|
||||
Plugin::List {} => {
|
||||
for item in tools::tool_list() {
|
||||
if tools::Tool::from_str(item).unwrap().is_installed() {
|
||||
println!("- {item} [installed]");
|
||||
} else {
|
||||
println!("- {item}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Plugin::AppPath {} => {
|
||||
if let Some(v) = tools::tools_path().to_str() {
|
||||
println!("{}", v);
|
||||
} else {
|
||||
log::error!("Tools path get failed.");
|
||||
}
|
||||
}
|
||||
Plugin::Add { name } => {
|
||||
let tool_list = tools::tool_list();
|
||||
|
||||
if !tool_list.contains(&name.as_str()) {
|
||||
log::error!("Tool {name} not found.");
|
||||
return Ok(());
|
||||
}
|
||||
let target_tool = tools::Tool::from_str(&name).unwrap();
|
||||
|
||||
if target_tool.is_installed() {
|
||||
log::warn!("Tool {name} is installed.");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
log::info!("Start to download tool package...");
|
||||
if let Err(e) = target_tool.download_package().await {
|
||||
log::error!("Tool download failed: {e}");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
log::info!("Start to install tool package...");
|
||||
if let Err(e) = target_tool.install_package().await {
|
||||
log::error!("Tool install failed: {e}");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
log::info!("Tool {name} install successfully!");
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user