Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing arguments to application when running yarn tauri dev #1406

Closed
yamgent opened this issue Mar 30, 2021 · 14 comments
Closed

Allow passing arguments to application when running yarn tauri dev #1406

yamgent opened this issue Mar 30, 2021 · 14 comments

Comments

@yamgent
Copy link

yamgent commented Mar 30, 2021

Is your feature request related to a problem? Please describe.
Tauri supports CLI, but we don't have a way to pass any arguments to the CLI when using yarn tauri dev.

Describe the solution you'd like
Support some way of passing in arguments, something like yarn tauri dev <arg1> <arg2> ...

Describe alternatives you've considered
Tried using the solution I mentioned above (yarn tauri dev <arg1> <arg2> ...) and it didn't work. I also tried just using cargo run <arg1> <arg2>..., which will pass in the arguments, but this is not workable because we need the wrapper provided by yarn tauri dev. So there's not really a feasible workaround for this.

Additional context
None

@lucasfernog
Copy link
Member

I'll implement this, it'll be yarn tauri dev -- <arg1> <arg2> ....

jbolda added a commit that referenced this issue Apr 11, 2021
* chore(deps) Update Tauri JS CLI (#1319)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps) Update Tauri Core (#1318)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps) Update Tauri API (#1316)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps) Update Rust crate serde_json to 1.0.64 (#1315)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps) Update Rust crate once_cell to 1.7.2 (#1314)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps) Update Rust crate image to 0.23.14 (#1313)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* feat(cli/build): improve no distDir error message (#1306)

* feat(cli/build): improve no distDir error message

* chore: use Path's Display impl

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>

* chore(deps) Update Tauri API Definitions (#1317)

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>

* feat(bundler/wix): install webview2 runtime (#1329)

* feat(bundler/wix): install webview2 runtime

* add changefile

* chore(deps) Update Tauri API Definitions (major) (#1290)

* chore(deps) Update Tauri API Definitions

* chore: update to husky v5

* chore: remove husky script

* chore: recreate lock file

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>

* chore(deps) Update Tauri JS CLI (#1291)

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>

* refactor(core): app hooks (#1332)

* fix(api/window): rename manager export to appWindow (#1342)

* feat(api/shell): allow open command to open files (#1341)

* chore(deps) Update Tauri API Definitions (#1344)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps) Update Rust crate tokio to 1.3 (#1343)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps) Update Rust crate open to 1.6.0 (#1348)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix(core): wrong usage of wry RPC on event API (#1351)

* copy cli config definition window visibility defaults (#1353)

* feat(core): add file drop handler (#1352)

* fix: get correct resource dir in AppImge (fix #1308) (#1333)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>

* feat: build without proc macros (#1226)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>

* chore(deps) Update Tauri JS CLI (#1346)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* refactor(core): use Mutex in std to reduce async usage (#1350)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>

* fix(examples): build error (#1354)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>

* API example new ui (#1310)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>

* chore(deps): remove `winres` from template (#1357)

* refactor(core): add `unlisten`, `once` APIs to the event system (#1359)

* fix(cli): use correct arg in `_blanks` links polyfill (#1362)

* fix(api/http): correct types (#1360)

* fix(api/http): correct types

* Add changes

* Update correct-http-api-types.md

* chore(deps) Update Tauri JS CLI (#1364)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps) Update Tauri API Definitions (#1363)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix(tauri/webview): Use different user_data_path for Windows (#1365) (#1366)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>

* fix(config): serde_json::Value::Object takes a Map instead of HashMap (#1371)

* fix(config): serde_json::Value::Object takes a Map instead of HashMap

* fix: fmt

* fix(tauri.js): init command properly building with manifests (#1374)

* fix(tauri.js): init command properly building with manifests

* fix: tests

* feat(bundler): add visual c++ redistributable files with MSM (#1368)

* refactor(core): reduce usage on arc and mutex (#1361)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>

* feat(config): allow setting product name and version on tauri.conf.json (#1358)

* feat: add current working directory to path api module (#1375)

* refactor(core): move bundle script to /tauri crate (#1377)

* refactor(core): move bundle script to /tauri crate

* fix(cli): clippy

* fix(core): tests

* refactor(core): custom protocol URL uses the app identifier (#1376)

* refactor(core): custom protocol URL uses the app identifier

* fix: clippy

* fix(tauri-api): remove .exe from app_name on windows (#1379)

* chore(deps) Update Tauri API Definitions (#1384)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps) Update Rust crate tokio to 1.4 (#1383)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix(cli): prmpt user before install deps in init (#1381)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>

* chore(deps) Update dependency rollup to v2.42.4 (#1386)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* refactor(cli): rewrite init command in Rust (#1382)

Co-authored-by: nothingismagick <denjell@mailscript.com>

* refactor(bundler): specific settings on dedicated structs, update README (#1380)

* replace lazy_static uses with once_cell (#1391)

* chore(deps) Update Tauri JS CLI (#1385)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* refactor(cli): rewrite info in Rust (#1389)

* refactor(core): remove async from app hooks, add InvokeMessage type (#1392)

* fix(cli): disable custom-protocol feature on dev command (#1393)

* Fix extremely slow dev builds caused by embedding + compressing assets at compile time (#1395)

* feat(bundler) code signing (#473)

Co-authored-by: Rajiv Shah <rajivshah1@icloud.com>
Co-authored-by: David Lemarier <david@lemarier.ca>

* feat(cli): run beforeDev and beforeBuild in a shell, closes #1295 (#1399)

* update to sharp 0.28.0 for cpu arm (m1) (#1404)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>

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

* refactor(api): use secure RNG, closes #1356 (#1398)

* chore(deps) Update Tauri API Definitions (#1411)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps) Update Rust crate rfd to 0.2.2 (#1410)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps) Update Tauri CLI (#1413)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps) Update Tauri Bundler (#1412)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* refactor(core): rewrite shell execute API, closes #1229 (#1408)

* chore(deps) Update dependency @rollup/plugin-commonjs to v18 (#1415)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* chore(deps) Update Tauri JS CLI (#1414)

Co-authored-by: Renovate Bot <bot@renovateapp.com>

* fix: asset resolution on debug mode

* fix(core): ignore query string on custom protocol asset resolver (#1420)

* wire up existing and adjust recipe configuration

* merge dev

* fix default app name

* clean up vanillajs and proper pass args

* use scaffe to copy the react templates

* fix(api): remove cjs, rename .mjs to .js

* chore: tauri.js dead code elim (#1422)

* remove templates, only used it CTA

* help command is empty, remove

* delete files that aren't imported / required

* set files array to ignore src and config files

* remove unused deps

* add arch notes for future ref

* change file

* allow specifying a binary

* resolve last bits to reach scaffe

* adjust vanilla js template dir path

Co-authored-by: Sanket Chaudhari <chaudharisanket2000@gmail.com>

* fix up cra scaffolding

* remove none and rely on vanillajs

* log shell commands

* remove no recipe question branch

* shift react template for better overwrite copying

* update deps

* simple readme

* implement dep manager

* pretty

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Noah Klayman <noahklayman@gmail.com>
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
Co-authored-by: Lucas Fernandes Nogueira <lucasfernandesnog@gmail.com>
Co-authored-by: chip <chip@chip.sh>
Co-authored-by: Gabe Cohen <gcc3.14@gmail.com>
Co-authored-by: Ngo Iok Ui (Wu Yu Wei) <wusyong9104@gmail.com>
Co-authored-by: Alve Larsson <larsalvelarsson@gmail.com>
Co-authored-by: Amr Bashir <48618675+amrbashir@users.noreply.github.com>
Co-authored-by: Kid <44045911+kidonng@users.noreply.github.com>
Co-authored-by: david <david@lemarier.ca>
Co-authored-by: nothingismagick <denjell@mailscript.com>
Co-authored-by: William <william@venner.io>
Co-authored-by: Rajiv Shah <rajivshah1@icloud.com>
Co-authored-by: Mehdi Rezaei <mehdiraized@gmail.com>
Co-authored-by: Sanket Chaudhari <chaudharisanket2000@gmail.com>
@Umenokin
Copy link

Hi folks,
I am still unable to make it work.

  "tauri": {
    "allowlist": {
      "all": true
    },
    "cli": {
      "description": "Test descript",
      "beforeHelp": "### BEFORE ###",
      "afterHelp": "### AFTER ###",
      "args": [{
        "name": "project",
        "short": "P",
        "takesValue": true,
        "multiple": false
      }]
    },

npm run tauri dev -- -- --project=test:

error: Found argument '--project' which wasn't expected, or isn't valid in this context

npm run tauri dev -- --project=test

error: Found argument '--project' which wasn't expected, or isn't valid in this context

cargo tauri dev --project=test

error: Found argument '--project' which wasn't expected, or isn't valid in this context

cargo tauri dev -- --project=test

error: Found argument '--project' which wasn't expected, or isn't valid in this context

And cargo tauri dev -- -- --project=test opens some built-in Welcome to Tauri!!! without running my JavaScript.

@amrbashir
Copy link
Member

I think npm run requires one moer -- try npm run tauri dev -- -- -- --project=test

@Umenokin
Copy link

Already did. Same as cargo tauri dev -- -- --project=test which would produce: 😅

 opens some built-in Welcome to Tauri!!! without running my JavaScript.

Though, I do think you right, npm requires one additional -- anyway

@amrbashir
Copy link
Member

The first -- allows you to pass to arguments to the runner (which is Cargo) and the second -- allows you to pass args to your app so

cargo tauri dev -- --cargo-arg1 --cargo-arg2 -- --app-arg1 --app-arg2

npm:

npm run tauri dev -- -- --cargo-arg1 --cargo-arg2 -- --app-arg1 --app-arg2

@FabianLars
Copy link
Member

opens some built-in Welcome to Tauri!!! without running my JavaScript.

Completely unrelated to the args tho. Welcome to Tauri is part of the templates and your javascript not loading shouldn't be caused by the args (unless you only inject it if args are provided) - either way not related to this issue so please create a new one (or a discussion because this doesn't look like a Tauri bug) or join our discord where triaging is much easier for us :)

@justintaylor-dev
Copy link

Also still unable to get this to work in tauri dev, any updates here?

@FabianLars
Copy link
Member

FabianLars commented Mar 1, 2023

@justintaylor-dev We're not aware of any problems i think. Can you share examples of what exactly you're having problems with (example commands and how you try to read the args)

Edit: just saw your discord discussion

@justintaylor-dev
Copy link

@FabianLars triple separators ended up working for me, thanks:

e.g.

yarn tauri dev -- -- -- --custom

@rkuzlik
Copy link

rkuzlik commented Mar 2, 2023

@FabianLars
I tried using the args also in the build command, but it does not work for me.
npm run tauri dev -- -- -- --mode x - works fine (I got the value as expected without any error)
npm run tauri build -- -- -- --mode x - failed
error: Found argument '--mode' which wasn't expected, or isn't valid in this context

any idea what could be the difference?

@FabianLars
Copy link
Member

That can't work because there is no application to forward the arguments to. Like in tauri dev tauri will forward the --mode x to the tauri app that's being opened, but in the build command the app won't be executed so tauri doesn't forward the arguments.

@rkuzlik
Copy link

rkuzlik commented Mar 2, 2023

We need to build the Tauri app twice in 2 modes, for each mode we need another implementation in the angular application.
(according to the provided mode we open another initialize route in the Angular app)
how can we implement it without arguments?

@FabianLars
Copy link
Member

I'm a bit confused here to be honest. I guess this depends on how exactly you implemented the modes.

If it is some kind of build time flag like ng build --configuration abc for example then i think you have to change the beforeBuildCommand (or don't use beforeBuildCommand at all and split it up into 2 steps 1) the frontend 2) the tauri app ). You can change the command by supplying a merge config with the -c / --config flag.

If the flag must be supplied when running the app (on the user's system) then it again, depends on the implementation i guess? Generally i don't think this can work in the way you're trying to do it here.

Can you give some kind of example on what you have and what you're actually trying to do?

@rkuzlik
Copy link

rkuzlik commented Mar 2, 2023

Thanks for your quick reply, using a different configuration for these 2 different modes seems to be more suitable for our needs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants