-
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
Bring belochub/jstp-cli upstream #107
Conversation
@lundibundi I've grabbed the latest patches. |
tools/cli.js
Outdated
completer | ||
}); | ||
|
||
const log = msg => { |
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.
@lundibundi can you please wrap msg
into parens here?
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 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.
This rule with as-needed
and requireForBlockBody
options enabled is exactly what we need. Would you like to open a PR for that?
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
const processor = lineProcessor[type]; | ||
if (!processor) { | ||
log(`Unknown command ${type}`); | ||
} else { |
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.
I'd prefer either the if branch to return from the function and reduce the indentation level for the code inside the else branch or to flip the condition. I don't feel very strongly for one way or other, but I like the first one more.
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 problem here is that using return is not the same as using else.
log(`Unknown command ${type}`); | ||
} else { | ||
processor(leftover, (err, result) => { | ||
if (err) return log(`${err.name} occurred: ${err.message}`); |
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.
I'd find it more readable to maybe use braces here.
tools/cli.js
Outdated
}; | ||
|
||
commandProcessor.call = (interfaceName, methodName, args, callback) => { | ||
if (state.client === null) return callback(new Error('Not connected')); |
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.
if (!state.client)
would be more readable here.
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.
Not sure about whether the braces would help readability since the next line is quite long too.
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.
@aqrln ok with !state.client
, but the braces will not help that much
tools/cli.js
Outdated
}; | ||
|
||
commandProcessor.event = (interfaceName, eventName, args, callback) => { | ||
if (state.client === null) return callback(new Error('Not connected')); |
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.
Ditto.
tools/cli.js
Outdated
log(`Received remote event: ${jstp.stringify(data)}`); | ||
}); | ||
callback(); | ||
}); |
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.
I'd prefer to put );
on a new 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.
sure
|
||
commandProcessor.connect = (host, port, appName, callback) => { | ||
state.client = jstp.tcp.createClient({ host, port, secure: true }); | ||
state.client.connectAndHandshake(appName, null, null, |
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.
And maybe appName, null, null,
too.
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 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.
It is okay either way, though I'd prefer to leave it as it is now.
tools/cli.js
Outdated
}; | ||
|
||
commandProcessor.disconnect = (callback) => { | ||
if (state.client !== null) { |
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.
if (state.client)
would 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.
sure
tools/cli.js
Outdated
const result = []; | ||
let start = 0; | ||
|
||
for (let i = 0; !limit || i < limit; i++) { |
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 intentional that zero limit is no limit?
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.
yes
tools/cli.js
Outdated
(err, connection) => { | ||
if (err) return callback(err); | ||
state.connection = connection; | ||
// todo make event registering generic |
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 proper spelling of todo
is TODO:
:) That'll make it highlighted in code editors and picked up by bitHound to be shown on the dashboard.
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.
oh, okay
tools/cli.js
Outdated
}); | ||
}; | ||
|
||
// map all remaining commands directly |
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.
Can you please start the comment with a capital letter?
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.
eh, meme, okay
@lundibundi for the record: commit your amendments based on the feedback from the review to this branch. |
eda3a57
to
de10f00
Compare
@belochub and @lundibundi, thank you a lot, you've done a great job shaping it up. I'm going to land this so that new improvements can be done incrementally as separate PRs, but it needs reviewers to sign-off the commits. All your commits LGTM, but I need you to review my de10f00 and I'd also like to know whether you have reviewed each other's commits. |
LGTM, it's good to be able to start it as usual shell command. Also yeah we have reviewed each other's commits so it's okay to land. |
@belochub just did it ;) Thanks! |
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
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, @aqrln, can you land it, please?
PR-URL: #107 Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
They are shown in the line next to the one user has been printing in and new prompt is shown with the user input copied to it. PR-URL: #107 Reviewed-By: Mykola Bilochub <nbelochub@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
PR-URL: #107 Reviewed-By: Mykola Bilochub <nbelochub@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Modify `_split` to push to array first substring of `str` which is not `splitter`, if limit is present and `leaveEmpty` set to false. PR-URL: #107 Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Move `cli.js` to `tools`, make it an executable script on its own and make NPM install an executable script named `jstp-cli` that points to `tools/cli.js`. PR-URL: #107 Reviewed-By: Mykola Bilochub <nbelochub@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Prompt was not displayed if unknown command was entered. PR-URL: #107 Reviewed-By: Mykola Bilochub <nbelochub@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Error message in 'disconnect' command was not transmitted correctly from commandProcessor by the lineProcessor to the caller. PR-URL: #107 Reviewed-By: Mykola Bilochub <nbelochub@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
This is a new and shiny first major release for `metarhia-jstp`. Changes include API refactoring and improvements, implementations of CLI, sessions, and application versions, native addon build optimizations, lots of bug fixes, test coverage increase, and other, less notable changes. This release also denotes the bump of the protocol version to v1.0. The only difference from the previous version of the protocol is that "old" heartbeat messages (`{}`) are now deprecated and `ping`/`pong` messages must be used for this purpose instead. Notable changes: * **src,build:** improve the native module subsystem *(Alexey Orlenko)* [#36](#36) **\[semver-minor\]** * **build:** compile in ISO C++11 mode *(Alexey Orlenko)* [#37](#37) **\[semver-minor\]** * **build:** improve error handling *(Alexey Orlenko)* [#40](#40) **\[semver-minor\]** * **lib:** refactor record-serialization.js *(Alexey Orlenko)* [#41](#41) **\[semver-minor\]** * **protocol:** change the format of handshake packets *(Alexey Orlenko)* [#54](#54) **\[semver-major\]** * **parser:** remove special case for '\0' literal *(Mykola Bilochub)* [#68](#68) **\[semver-major\]** * **client:** drop redundant callback argument *(Alexey Orlenko)* [#104](#104) **\[semver-major\]** * **client:** handle errors in connectAndInspect *(Alexey Orlenko)* [#105](#105) **\[semver-major\]** * **socket,ws:** use socket.destroy() properly *(Alexey Orlenko)* [#84](#84) **\[semver-major\]** * **cli:** add basic implementation *(Mykola Bilochub)* [#107](#107) **\[semver-minor\]** * **connection:** fix error handling in optional cbs *(Alexey Orlenko)* [#147](#147) **\[semver-major\]** * **lib:** change event signature *(Denys Otrishko)* [#187](#187) **\[semver-major\]** * **lib:** add address method to Server *(Denys Otrishko)* [#190](#190) **\[semver-minor\]** * **lib:** optimize connection events *(Denys Otrishko)* [#222](#222) **\[semver-major\]** * **lib:** refactor server and client API *(Denys Otrishko)* [#209](#209) **\[semver-major\]** * **lib,src:** rename term packet usages to message *(Denys Otrishko)* [#270](#270) **\[semver-major\]** * **lib:** emit events about connection messages *(Denys Otrishko)* [#252](#252) **\[semver-minor\]** * **connection:** make callback method private *(Alexey Orlenko)* [#306](#306) **\[semver-major\]** * **lib:** implement sessions *(Mykola Bilochub)* [#289](#289) **\[semver-major\]** * **connection:** use ping-pong instead of heartbeat *(Dmytro Nechai)* [#303](#303) **\[semver-major\]**
This is a new and shiny first major release for `metarhia-jstp`. Changes include API refactoring and improvements, implementations of CLI, sessions, and application versions, native addon build optimizations, lots of bug fixes, test coverage increase, and other, less notable changes. This release also denotes the bump of the protocol version to v1.0. The only difference from the previous version of the protocol is that "old" heartbeat messages (`{}`) are now deprecated and `ping`/`pong` messages must be used for this purpose instead. Notable changes: * **src,build:** improve the native module subsystem *(Alexey Orlenko)* [#36](#36) **\[semver-minor\]** * **build:** compile in ISO C++11 mode *(Alexey Orlenko)* [#37](#37) **\[semver-minor\]** * **build:** improve error handling *(Alexey Orlenko)* [#40](#40) **\[semver-minor\]** * **lib:** refactor record-serialization.js *(Alexey Orlenko)* [#41](#41) * **parser:** fix a possible memory leak *(Alexey Orlenko)* [#44](#44) **\[semver-minor\]** * **protocol:** change the format of handshake packets *(Alexey Orlenko)* [#54](#54) **\[semver-major\]** * **parser:** make parser single-pass *(Mykola Bilochub)* [#61](#61) * **parser:** remove special case for '\0' literal *(Mykola Bilochub)* [#68](#68) **\[semver-major\]** * **parser:** fix bug causing node to crash *(Mykola Bilochub)* [#75](#75) * **client:** drop redundant callback argument *(Alexey Orlenko)* [#104](#104) **\[semver-major\]** * **client:** handle errors in connectAndInspect *(Alexey Orlenko)* [#105](#105) **\[semver-major\]** * **socket,ws:** use socket.destroy() properly *(Alexey Orlenko)* [#84](#84) **\[semver-major\]** * **cli:** add basic implementation *(Mykola Bilochub)* [#107](#107) **\[semver-minor\]** * **connection:** fix error handling in optional cbs *(Alexey Orlenko)* [#147](#147) **\[semver-major\]** * **test:** add JSON5 specs test suite *(Alexey Orlenko)* [#158](#158) * **lib:** change event signature *(Denys Otrishko)* [#187](#187) **\[semver-major\]** * **lib:** add address method to Server *(Denys Otrishko)* [#190](#190) **\[semver-minor\]** * **parser:** implement NaN and Infinity parsing *(Mykola Bilochub)* [#201](#201) * **parser:** improve string parsing performance *(Mykola Bilochub)* [#220](#220) * **lib:** optimize connection events *(Denys Otrishko)* [#222](#222) **\[semver-major\]** * **lib:** refactor server and client API *(Denys Otrishko)* [#209](#209) **\[semver-major\]** * **lib,src:** rename term packet usages to message *(Denys Otrishko)* [#270](#270) **\[semver-major\]** * **lib:** emit events about connection messages *(Denys Otrishko)* [#252](#252) **\[semver-minor\]** * **lib:** implement API versioning *(Denys Otrishko)* [#231](#231) **\[semver-minor\]** * **lib:** allow to set event handlers in application *(Denys Otrishko)* [#286](#286) **\[semver-minor\]** * **lib:** allow to broadcast events from server *(Denys Otrishko)* [#287](#287) **\[semver-minor\]** * **connection:** make callback method private *(Alexey Orlenko)* [#306](#306) **\[semver-major\]** * **lib:** implement sessions *(Mykola Bilochub)* [#289](#289) **\[semver-major\]** * **connection:** use ping-pong instead of heartbeat *(Dmytro Nechai)* [#303](#303) **\[semver-major\]**
PR-URL: metarhia/jstp#107 Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
* Fix code style * Fix error handling - show only error message without stacktrace * Make split work for separator of multiple characters * Fix map usage * Other bugfixes * General code refactoring PR-URL: metarhia/jstp#107 Reviewed-By: Mykola Bilochub <nbelochub@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
PR-URL: metarhia/jstp#107 Reviewed-By: Mykola Bilochub <nbelochub@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
PR-URL: metarhia/jstp#107 Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
They are shown in the line next to the one user has been printing in and new prompt is shown with the user input copied to it. PR-URL: metarhia/jstp#107 Reviewed-By: Mykola Bilochub <nbelochub@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
PR-URL: metarhia/jstp#107 Reviewed-By: Mykola Bilochub <nbelochub@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Modify `_split` to push to array first substring of `str` which is not `splitter`, if limit is present and `leaveEmpty` set to false. PR-URL: metarhia/jstp#107 Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Move `cli.js` to `tools`, make it an executable script on its own and make NPM install an executable script named `jstp-cli` that points to `tools/cli.js`. PR-URL: metarhia/jstp#107 Reviewed-By: Mykola Bilochub <nbelochub@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Prompt was not displayed if unknown command was entered. PR-URL: metarhia/jstp#107 Reviewed-By: Mykola Bilochub <nbelochub@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Error message in 'disconnect' command was not transmitted correctly from commandProcessor by the lineProcessor to the caller. PR-URL: metarhia/jstp#107 Reviewed-By: Mykola Bilochub <nbelochub@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
PR-URL: metarhia/jstp#107 Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
* Fix code style * Fix error handling - show only error message without stacktrace * Make split work for separator of multiple characters * Fix map usage * Other bugfixes * General code refactoring PR-URL: metarhia/jstp#107 Reviewed-By: Mykola Bilochub <nbelochub@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
PR-URL: metarhia/jstp#107 Reviewed-By: Mykola Bilochub <nbelochub@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
PR-URL: metarhia/jstp#107 Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
They are shown in the line next to the one user has been printing in and new prompt is shown with the user input copied to it. PR-URL: metarhia/jstp#107 Reviewed-By: Mykola Bilochub <nbelochub@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
PR-URL: metarhia/jstp#107 Reviewed-By: Mykola Bilochub <nbelochub@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Modify `_split` to push to array first substring of `str` which is not `splitter`, if limit is present and `leaveEmpty` set to false. PR-URL: metarhia/jstp#107 Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Move `cli.js` to `tools`, make it an executable script on its own and make NPM install an executable script named `jstp-cli` that points to `tools/cli.js`. PR-URL: metarhia/jstp#107 Reviewed-By: Mykola Bilochub <nbelochub@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Prompt was not displayed if unknown command was entered. PR-URL: metarhia/jstp#107 Reviewed-By: Mykola Bilochub <nbelochub@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Error message in 'disconnect' command was not transmitted correctly from commandProcessor by the lineProcessor to the caller. PR-URL: metarhia/jstp#107 Reviewed-By: Mykola Bilochub <nbelochub@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
I've created a branch to port belochub/jstp-cli to be a part of JSTP itself, as it was agreed upon in https://github.com/belochub/jstp-cli/issues/1.
Right now
cli.js
is located in the root of the project in order to mirror the original repo and make cherry-picking new commits effortless. It should later be separated intobin/cli.js
andlib/cli/*.js
./cc @belochub @lundibundi