瀏覽代碼

fix(cli.rs): do not prompt for `init` values if arg set (#3400)

Lucas Fernandes Nogueira 3 年之前
父節點
當前提交
def7684025
共有 2 個文件被更改,包括 34 次插入23 次删除
  1. 5 0
      .changes/fix-cli-prompts.md
  2. 29 23
      tooling/cli/src/init.rs

+ 5 - 0
.changes/fix-cli-prompts.md

@@ -0,0 +1,5 @@
+---
+"cli.rs": patch
+---
+
+Fix `init` command prompting for values even if the argument has been provided on the command line.

+ 29 - 23
tooling/cli/src/init.rs

@@ -90,29 +90,35 @@ impl Options {
       Default::default()
     };
 
-    self.app_name = self.app_name.or(request_input(
-      "What is your app name?",
-      init_defaults.app_name.clone(),
-      self.ci,
-    )?);
-
-    self.window_title = self.window_title.or(request_input(
-      "What should the window title be?",
-      init_defaults.app_name.clone(),
-      self.ci,
-    )?);
-
-    self.dist_dir = self.dist_dir
-                .or(request_input(
-                    r#"Where are your web assets (HTML/CSS/JS) located, relative to the "<current dir>/src-tauri/tauri.conf.json" file that will be created?"#,
-                    init_defaults.framework.as_ref().map(|f| f.dist_dir()),
-                    self.ci)?);
-
-    self.dev_path = self.dev_path.or(request_input(
-      "What is the url of your dev server?",
-      init_defaults.framework.map(|f| f.dev_path()),
-      self.ci,
-    )?);
+    self.app_name = self.app_name.map(|s| Ok(Some(s))).unwrap_or_else(|| {
+      request_input(
+        "What is your app name?",
+        init_defaults.app_name.clone(),
+        self.ci,
+      )
+    })?;
+
+    self.window_title = self.window_title.map(|s| Ok(Some(s))).unwrap_or_else(|| {
+      request_input(
+        "What should the window title be?",
+        init_defaults.app_name.clone(),
+        self.ci,
+      )
+    })?;
+
+    self.dist_dir = self.dist_dir.map(|s| Ok(Some(s))).unwrap_or_else(|| request_input(
+      r#"Where are your web assets (HTML/CSS/JS) located, relative to the "<current dir>/src-tauri/tauri.conf.json" file that will be created?"#,
+      init_defaults.framework.as_ref().map(|f| f.dist_dir()),
+      self.ci
+    ))?;
+
+    self.dev_path = self.dev_path.map(|s| Ok(Some(s))).unwrap_or_else(|| {
+      request_input(
+        "What is the url of your dev server?",
+        init_defaults.framework.map(|f| f.dev_path()),
+        self.ci,
+      )
+    })?;
 
     Ok(self)
   }