Sfoglia il codice sorgente

feat(cli): propagate args passed after `dev --`, closes #1406 (#1407)

Lucas Fernandes Nogueira 4 anni fa
parent
commit
4e9d31c70b

+ 6 - 0
.changes/tauri-dev-propagate-args.md

@@ -0,0 +1,6 @@
+---
+"tauri-cli": patch
+"tauri.js": patch
+---
+
+All the arguments passed after `tauri dev --` are now propagated to the binary.

+ 5 - 0
cli/core/src/cli.yml

@@ -8,6 +8,7 @@ subcommands:
       subcommands:
         - dev:
             about: Tauri dev.
+            setting: TrailingVarArg
             args:
                 - config:
                     short: c
@@ -18,6 +19,10 @@ subcommands:
                     short: e
                     long: exit-on-panic
                     about: Exit on panic
+                - args:
+                    about: Args passed to the binary
+                    index: 1
+                    multiple: true
         - build:
             about: Tauri build.
             args:

+ 9 - 0
cli/core/src/dev.rs

@@ -32,6 +32,7 @@ fn kill_before_dev_process() {
 pub struct Dev {
   exit_on_panic: bool,
   config: Option<String>,
+  args: Vec<String>,
 }
 
 impl Dev {
@@ -49,6 +50,11 @@ impl Dev {
     self
   }
 
+  pub fn args(mut self, args: Vec<String>) -> Self {
+    self.args = args;
+    self
+  }
+
   pub fn run(self) -> crate::Result<()> {
     let logger = Logger::new("tauri:dev");
     let tauri_path = tauri_dir();
@@ -149,6 +155,9 @@ impl Dev {
   fn start_app(&self, child_wait_rx: Arc<Mutex<Receiver<()>>>) -> Arc<SharedChild> {
     let mut command = Command::new("cargo");
     command.args(&["run", "--no-default-features"]);
+    if !self.args.is_empty() {
+      command.arg("--").args(&self.args);
+    }
     let child = SharedChild::spawn(&mut command).expect("failed to run cargo");
     let child_arc = Arc::new(child);
 

+ 5 - 1
cli/core/src/main.rs

@@ -80,8 +80,12 @@ fn init_command(matches: &ArgMatches) -> Result<()> {
 fn dev_command(matches: &ArgMatches) -> Result<()> {
   let exit_on_panic = matches.is_present("exit-on-panic");
   let config = matches.value_of("config");
+  let args: Vec<String> = matches
+    .values_of("args")
+    .map(|a| a.into_iter().map(|v| v.to_string()).collect())
+    .unwrap_or_default();
 
-  let mut dev_runner = dev::Dev::new().exit_on_panic(exit_on_panic);
+  let mut dev_runner = dev::Dev::new().exit_on_panic(exit_on_panic).args(args);
 
   if let Some(config) = config {
     dev_runner = dev_runner.config(config.to_string());