-
Notifications
You must be signed in to change notification settings - Fork 1k
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
More improvements to the way CLI handles comments in multi-line statements #2241
More improvements to the way CLI handles comments in multi-line statements #2241
Conversation
…-line statements.
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 @big-andy-coates . Super comprehensive comment support! LGTM.
|
||
private String parse() { | ||
final String firstPart = strip(); | ||
if (done()) { |
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.
The reason this isn't wrapped into the while-loop below is so we avoid creating a StringBuilder
instance when the line contains no comments, yes? How expensive is it to create a StringBuilder
instance? (Trying to improve my understanding of when such optimizations make sense.)
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.
Most lines won't have comments, hence I added this early out as its easy to do.
One could argue this is 'premature optimisation' - especially considering this is, in general, reacting to someone typing at a keyboard and hence performance isn't really an issue. So asking me to remove this would be a valid point.
Pretty slick-looking Andy! But i'm not sure i like the trade-off here of giving up good history presentation (i.e. the way it works today, which i think is likely the most 'expected' way for such a thing to work) to get even better inline commenting. Is there a way to resolve that tension by tweaking the impl here ? If not, i'd personally vote against making this particular change. |
Hey @blueedgenick, You're feedback welcome as always! I had a quick look at the current CLI and it too reports multiple line history over multiple lines, (by bad, I'd not checked this wasn't already the case): version 5.0.x gives:
With the change to drop line continuation char this now becomes:
So, there isn't really any change to history output here! |
@big-andy-coates fair point! ideally the history lines would get condensed into a single-line presentation (which for some reason i thought they already were, but that could just be a sign of the state of my memory). And of course once condensed into a single line it doesn't make sense to have the embedded comments any more... not saying we shouldn't preserve the comments, as entered, in the command topic - i'm only addressing the presentation of the local history file entries here. WDYT ? |
Agreed, this is a cosmetic change. I wouldn't block this PR on it. Rather, we should file a separate GH ticket to consider improving the presentation of the (local) history of commands. |
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.
LGTM!
Hey @blueedgenick, Personally, I think a multi-line command should be displayed in the history output over multiple lines. However, I don't feel strongly about it. As @miguno suggests, how about raising an issue with details of how you think it should work? You could mark the issue as |
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.
Is it worth adding a test to CliTest
?
LGTM
I'm happy with the test coverage. Combination of |
* fork/master: (107 commits) copy-edited (confluentinc#2299) copy-edited (confluentinc#2299) remove unused map from command store `getRestoreCommands` (confluentinc#2296) Speed up integration tests. (confluentinc#2288) Move KSQL Clickstream demo to Examples repo (confluentinc#2270) Bump Confluent to 5.1.1-SNAPSHOT, Kafka to 2.1.1-SNAPSHOT Set Confluent to 5.1.0, Kafka to 2.1.0-cp1. Add ServiceContext (confluentinc#2243) Update to use CCL (confluentinc#2278) Remove redundant intro sentence in README.md (confluentinc#2277) Switch to use CCL (confluentinc#2275) Update readme for CCL (confluentinc#2276) Minor: add Hamcrest matchers for KsqlRestException and KsqlErrorMessage (confluentinc#2273) Update per relicensing (confluentinc#2274) CP-584: 5.1.0 changelog (confluentinc#2267) add null checks to min, max, and count aggregates; call Math.min/max for consistency (confluentinc#2246) Return and accept command topic offsets via REST API (confluentinc#2159) MINOR: Fix bug encountered when restoring RUN SCRIPT command. (again) (confluentinc#2265) More improvements to the way the CLI handles inline comments in multi-line statements. (confluentinc#2241) Fix issue where Avro subject does not exist (confluentinc#2260) ...
Description
Following on from @vcrfxia insights in the last pr: #2214 (review), this PR adds more improvements to the way the CLI handles inline comments.
It can now handle something like this example being cut and paste into the CLI:
To support I've enhanced the
CommentStripper
to handle multi-line statements with embedded comments.I've also had to switch the
JLineReader
to not replace new lines with spaces. So if the input contains multiple lines, so does the output. But the parser is fine with this. History also still works, though a single history item can now span multiple lines, e.g. running:Works, and then you can list history, which shows the command over multiple lines:
Testing done
Added appropriate unit test and manual sanity testing.
Reviewer checklist