-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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 RuntimeHooks toq be set in command line #1404
Conversation
* @param line | ||
* @return | ||
*/ | ||
public static Main parseKarateOptionAndQuotePath(String line) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is one utility created in Command
here it is:
this is intended for parsing any command line into a string array, can you see if that is sufficient or improve it
then hopefully the existing logic to parse the last option a path
should be sufficient
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I think I understood Command.tokenize(), let me explain why I wrote it like this..
it's going to take me a few lines to put this in common
Karate and Picocli supports multiple options and parameters (whould be paths for karate) as long as they are quoted if they contain spaces
-X option one.feature "with spaces.feature"
so this would work ok if called using Main.main(String[] args)
but if called from the IDEs it would came as a single String format, that is why Command.tokenize() should be used instead of string.split()
the problem is that IDEs (both intellij, vscode and probably eclipse) sends the feature path as an unquoted string even if it contains spaces :-(
until now the IdeMain class didn't make use of karateOptions, it just accepted a single string as the path (after sanitizing unknown options like --monochrome)
https://github.com/intuit/karate/blob/develop/karate-core/src/main/java/com/intuit/karate/cli/IdeMain.java#L103
Parsing a line like this -H runtimeHook this feature has spaces.feature
using picocli would give you 1 option + 4 paths (instead of one) (Now it worked because it wasn't parsed for other options with picocli)
The function that I wrote, what it does is quoting last parameter and then it delegates to original IdeMain.parseKarateOptions that uses Command.tokenize()
It will produce -H runtimeHook "this feature has spaces.feature"
that will split as expected in 3 strings by Command.tokenize()
(Caveant: parseKarateOptionAndQuotePath
works only if there is one single path with no further options after path (it's the last one) which is compatible with what ides send.. And as I understand two unquoted paths with spaces would be an imposible task)
Now, DapServer uses IdeMain.parseIdeCommandLine(launchCommand) but fas as I know debuging only works from VSCode
https://github.com/intuit/karate/blob/develop/karate-core/src/main/java/com/intuit/karate/debug/DapServerHandler.java#L398
Does it makes more sense creating the quoting function just to be used in this DapServerHandler instead of inside IdeMain.parseIdeCommandLine ?
But this will leave other IDEs out of the ability to configure RuntimeHooks on the command line (not even sure if this is posible)...
just leaving it for a few days and sorry about this long story..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the long explanation, it makes sense, I'll merge 👍
@ivangsa I made just one minor change using |
Description
This PR allows to set RuntimeHooks from command line options when using Main cli.
I'm planning to use these hooks to send runtime information to vscode over a socket in order to implement network logs and other functionality.