Electron-forge: Ability to pass additional arguments to Electron via electron-forge-start

Created on 3 Apr 2017  路  10Comments  路  Source: electron-userland/electron-forge

  • [x] I have read the contribution documentation for this project.
  • [x] I agree to follow the code of conduct that this project follows, as appropriate.
  • [x] I have searched the issue tracker for an issue that matches the one I want to file, without success.

This is less of a bug and more of a suggestion/improvement.

I am working on an Electron application that has two modes of operation (player and editor). By default the player is started unless the --editor flag is present on the CLI. In that case, the editor is launched.

I would definitely be useful to be able to pass CLI arguments to the Electron application via electron-forge start.

Currently, passing anything that is not a valid option for electron-forge-start will cause the command to halt on the fact it doesn't understand the argument, meaning I have to either package my application to test the CLI flags or launch my application via node_modules/.bin/electron, which defeats the purpose of electron-forge start.

Most helpful comment

Any chance someone could show an example? I'm having trouble.
Executing as follows:
electron-forge start --- arg1value arg2value

Is this the correct format? If so, how can they be accessed in main.js? Trying with process.argv to no avail.

Electron version: 1.8.2

UPDATE:
Ahh, just so #209. For anyone coming to this issue, it's been updated to require two dashes:
electron-forge start -- arg1value arg2value

They are indeed accessible via process.argv

Thanks team!

All 10 comments

@glek Poorly documented but any argument after --- will be passed through to your application.

I.e.

electron-forge start --- arg1 arg2 --editor

Will improve the docs for this on the site 馃憤

Yes, I just found this in the code after digging around. Definitely needs better documentation. Thanks!

Just found this as well鈥攆wiw, I think the delimiter for arguments passed into the child process is usually -- and not ---? Might just be my experience but I spent a while trying two dashes instead of three... Glad to see this is supported though!

@bengotow Hm, that does actually make sense, most things I know do use -- to pass through args.

@malept How would you feel about changing it to a double dash in the upcoming breaking change version bump?

@MarshallOfSound I'm fine with that. I thought it was rather odd that it was a triple dash, but I figured you had a reason 馃槃

@malept Don't think I implemented it 馃槅

Any chance someone could show an example? I'm having trouble.
Executing as follows:
electron-forge start --- arg1value arg2value

Is this the correct format? If so, how can they be accessed in main.js? Trying with process.argv to no avail.

Electron version: 1.8.2

UPDATE:
Ahh, just so #209. For anyone coming to this issue, it's been updated to require two dashes:
electron-forge start -- arg1value arg2value

They are indeed accessible via process.argv

Thanks team!

did anyone try this method and did it work successfully? I tried to pass --- myArg and got errors like this:

$ yarn start --- --lang=fr
yarn run v1.12.3
$ electron-forge start --- --lang=fr
error: unknown option `---'
error Command failed with exit code 1.

Note that I used yarn to call electron-forge.
electron-forge version:

鈹斺攢 [email protected]
Was this page helpful?
0 / 5 - 0 ratings