Browse Source

Minor improvments.

Ell 2 years ago
parent
commit
9f238fa464
3 changed files with 13 additions and 9 deletions
  1. 6 4
      src/cli/plugin/mod.rs
  2. 6 4
      src/plugin/mod.rs
  3. 1 1
      src/tools.rs

+ 6 - 4
src/cli/plugin/mod.rs

@@ -21,10 +21,12 @@ impl Plugin {
                 }
                 }
             }
             }
             Plugin::AppPath {} => {
             Plugin::AppPath {} => {
-                if let Some(v) = crate::plugin::PluginManager::init_plugin_dir().to_str() {
-                    println!("{}", v);
-                } else {
-                    log::error!("Plugin path get failed.");
+                if let Ok(plugin_dir) = crate::plugin::PluginManager::init_plugin_dir() {
+                    if let Some(v) = plugin_dir.to_str() {
+                        println!("{}", v);
+                    } else {
+                        log::error!("Plugin path get failed.");
+                    }
                 }
                 }
             }
             }
             Plugin::Add { name: _ } => {
             Plugin::Add { name: _ } => {

+ 6 - 4
src/plugin/mod.rs

@@ -42,7 +42,7 @@ impl PluginManager {
         let manager = lua.create_table().unwrap();
         let manager = lua.create_table().unwrap();
         let name_index = lua.create_table().unwrap();
         let name_index = lua.create_table().unwrap();
 
 
-        let plugin_dir = Self::init_plugin_dir();
+        let plugin_dir = Self::init_plugin_dir().unwrap();
 
 
         let api = lua.create_table().unwrap();
         let api = lua.create_table().unwrap();
 
 
@@ -288,15 +288,17 @@ impl PluginManager {
         Ok(())
         Ok(())
     }
     }
 
 
-    pub fn init_plugin_dir() -> PathBuf {
+    pub fn init_plugin_dir() -> anyhow::Result<PathBuf> {
         let app_path = app_path();
         let app_path = app_path();
         let plugin_path = app_path.join("plugins");
         let plugin_path = app_path.join("plugins");
         if !plugin_path.is_dir() {
         if !plugin_path.is_dir() {
             log::info!("📖 Start to init plugin library ...");
             log::info!("📖 Start to init plugin library ...");
             let url = "https://github.com/DioxusLabs/cli-plugin-library";
             let url = "https://github.com/DioxusLabs/cli-plugin-library";
-            clone_repo(&plugin_path, url).unwrap();
+            if let Err(err) = clone_repo(&plugin_path, url) {
+                log::error!("Failed to init plugin dir, error caused by {}. ", err);
+            }
         }
         }
-        plugin_path
+        Ok(plugin_path)
     }
     }
 
 
     pub fn plugin_list() -> Vec<String> {
     pub fn plugin_list() -> Vec<String> {

+ 1 - 1
src/tools.rs

@@ -49,7 +49,7 @@ pub fn clone_repo(dir: &Path, url: &str) -> anyhow::Result<()> {
     let res = cmd.arg("clone").arg(url).arg(dir_name).output();
     let res = cmd.arg("clone").arg(url).arg(dir_name).output();
     if let Err(err) = res {
     if let Err(err) = res {
         if ErrorKind::NotFound == err.kind() {
         if ErrorKind::NotFound == err.kind() {
-            log::error!("Git program not found. Hint: Install git or check $PATH.");
+            log::warn!("Git program not found. Hint: Install git or check $PATH.");
             return Err(err.into());
             return Err(err.into());
         }
         }
     }
     }