-
Notifications
You must be signed in to change notification settings - Fork 10
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
parse vs parseAndExit #25
Comments
I am AFK right now, but concerning when to use
|
OK Most of the time but: So: If I use only So you can probably see the predicament. If I use one or the other, which would you suggest, and how would you suggest I work around the issues that come with either of the options? Thanks. |
There's no magic to Lines 574 to 583 in 7e7eff1
You could do something similar. If help was requested, or if there is an error to report, the content to display will be given in |
Understood, but this doesn't seem to be working. As I mentioned above, when I run Do I need to add something extra to the Thanks. |
What you describe is known as "strict" mode in yargs. Sywac does not support "strict" mode out-of-the-box; rather, any unknown flags are parsed on a best-effort basis and added as keys in If you want to use "strict" mode with sywac, you'll need to write some custom validation code. I recommend using a |
I replaced my I see there is a check for I also see on the
I noticed that when I used Thanks. |
How about something like this? https://gitlab.com/nexdrew/purpleteam/compare/master...fix-cli If you pass unknown args to the If you pass unknown flags, they are simply ignored and the command is run. If you pass an unknown command, the top-level help content is displayed (this is due to One thing I noticed is that you are catching API errors in the code that is called by the |
This seems to work well, except...
This is why I was using I'm also re-throwing any app errors which I would have thought would bubble up for the CLI code to display and exit, but they don't. How should a sywac consumer deal with these? I also didn't realise that the Thanks very much for helping so far! |
Thoughts @nexdrew ? |
Any unhandled errors will bubble up to sywac and sywac will handle them and report them in the The error handling I was talking about in your code is found here: https://gitlab.com/purpleteam-labs/purpleteam/blob/49e1341ca37f0b5f81cd239f92b9f86344c51f97/src/presenter/apiDecoratingAdapter.js#L50-77 Since it catches the error from the rejected Promise and doesn't re-throw it or notify sywac, the CLI code doesn't know that any error occurred. This is what I see: $ NODE_ENV=test ./bin/purpleteam test -c ./testResources/jobs/job_0.1.0-alpha.1
▶ debug [index] Starting the CLI
▶ debug [cli] Configuring sywac
✖ critical [apiDecoratingAdapter] Error occurred while attempting to communicate with the purpleteam SaaS. Error was: "The purpleteam backend is currently unreachable".
$ echo $?
0 How you want to handle this is entirely up to you. Perhaps the easiest thing might be to set let response
try {
response = await something()
} catch (err) {
handleError(err)
process.exitCode = 1
} |
I'm closing this issue as I believe I have fully answered the question about when to use |
Hi @nexdrew
What's the correct "recommended" way to establish whether to
parse
orparseAndExit
?I have the following code (cli.js) which feels a bit dirty and is also missing a few cases... which I think
sywac should be dealing with. For example, when a user runs the CLI with
test <unknownOption>
parseAndExit
executes mytest
command and I'm expecting the command to handle and spit out the specific command (test
in my case) help along with a contextual help error message, which doesn't happen.Also when a user runs the CLI with an (any) unknown command (for example
testttt
), just the generic help is displayed, I think sywac can and usually does also produce a contextual error message which is not currently the case. Am I doing something incorrectly here?cli.js
The test command (test.js)
Thanks.
The text was updated successfully, but these errors were encountered: