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 RuntimeHooks toq be set in command line #1404

Merged
merged 4 commits into from
Dec 19, 2020

Conversation

ivangsa
Copy link
Contributor

@ivangsa ivangsa commented Dec 17, 2020

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.

@ivangsa ivangsa requested a review from ptrthomas December 18, 2020 20:08
* @param line
* @return
*/
public static Main parseKarateOptionAndQuotePath(String line) {
Copy link
Member

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:

https://github.com/intuit/karate/blob/develop/karate-core/src/main/java/com/intuit/karate/shell/Command.java#L123-L134

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

Copy link
Contributor Author

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..

Copy link
Member

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 👍

@ptrthomas ptrthomas merged commit 8e9232c into karatelabs:develop Dec 19, 2020
ptrthomas added a commit that referenced this pull request Dec 19, 2020
@ptrthomas
Copy link
Member

@ivangsa I made just one minor change using --hook instead of --hooks for the long-form cli option

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

Successfully merging this pull request may close these issues.

2 participants