-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Issue parsing nested commands with electron app #1894
Comments
There is code to auto-detect Electron to change the expected argument conventions, or you can explicitly specify the convention when needed. See https://github.com/tj/commander.js#parse-and-parseasync Can you give some reproduce steps for the problem you are seeing with Electron? |
Thanks for the helpful and prompt reply. Calling parse without any arguments solved the issue as implicit electron handling kicked in. Two follow-up question thoughs (which might be answered but could not find on my own), first the program displays help if there are no commands and i need to avoid that, and other issue being there is still issue if I have to use options meant for the calling exe (electron.exe) e.g $myprogram.exe --inspect-brk brew coffee If i do this, it correctly passes inspect-brk to the electron app and i can debug the script from chrome://inspect, however, during parse, i get the error below. Please let me know if you are aware of a way to get around this issue. Extra info: For steps, please follow Electron quickstart basically copy pasting code for all files required + adding latest commander js. Then copy paste code from examples/nestedcommands.js file at the start of main/index.js and do the top level require to 'normal include'. That is it!!! |
Node strips the node specific command-line arguments like You could add a dummy argument and strip the earlier arguments before passing the remaining arguments to Commander. e.g.
Another approach would be to add the node options you intent to use as known options, so Commander silently consumes them:
|
One way of handling this is to add a default command. Look for A slightly simpler approach if you aren't using options for the no-subcommand case is just to add an action handler to the program. This gets called if no subcommand is specified. |
Thanks for quick help and support in resolving the issues. The empty action handler did fix most of the issues. I used the allow UnknownOption as well to get past the inspect-brk problem. Closing the issue now. |
The nestedcommands.js file in examples seem to work fine if launched directly from node, but fails if called from packaged app like electron (pretty similar to #512)
The issue seems to be that the parsing logic seems to be expecting two entries (node.exe path followed by script file path) in process.argv passed to program.parse before actual command arguments. For node, both entries exist, whereas in electron, there is only one entry i.e. name of executable.
The problem can be reproduced even without electron with steps below
In the nestedcommands.js file linked above in your examples folder, try passing hard coded array to program.parse line (line 42 currently). I added !!! to console.logs in action handlers for clarity.
Now remove any of the first two arguments abc or def
Similar case with process.argv with second entry (file path) removed and only executable (say node.exe) path present in call to program.parse.
The text was updated successfully, but these errors were encountered: