Skip to content

Commit

Permalink
feat(cli): propagate args passed after dev --, closes #1406 (#1407)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Mar 30, 2021
1 parent 9fc2385 commit 4e9d31c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changes/tauri-dev-propagate-args.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri-cli": patch
"tauri.js": patch
---

All the arguments passed after `tauri dev --` are now propagated to the binary.
5 changes: 5 additions & 0 deletions cli/core/src/cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ subcommands:
subcommands:
- dev:
about: Tauri dev.
setting: TrailingVarArg
args:
- config:
short: c
Expand All @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions cli/core/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ fn kill_before_dev_process() {
pub struct Dev {
exit_on_panic: bool,
config: Option<String>,
args: Vec<String>,
}

impl Dev {
Expand All @@ -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();
Expand Down Expand Up @@ -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);

Expand Down
6 changes: 5 additions & 1 deletion cli/core/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 4e9d31c

Please sign in to comment.