-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Bug fix: create utility for dealing with help input #5871
Conversation
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.
Some small nits.
packages/core/lib/cliHelp.js
Outdated
let displayHelp = false; | ||
//User only enter truffle with no commands, let's show them what's available. | ||
if (inputStrings.length === 0) { | ||
displayHelp = true; |
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 code can return true
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.
No it can't, that does not conform to the method signature as I wrote it :)
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 do you mean to return { displayHelp: true }
in both of these cases?
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, { displayHelp: true }
in both of those cases.
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 but that is more a stylistic thing than anything.
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 consider it to be a readability refactor. The current iteration makes it easier to understand the success path of the function. It reduces the need to track displayHelp
's state throughout the function, as well as clearly outlining the exceptional, failure, cases with the early returns.
Edit: I can see where it can come down to stylistic choices. At times, I like to initialize a result
variable and change its state until returning it. This article nicely summarizes the return early pattern
4d277e5
to
18e4148
Compare
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.
Looks good to me, pending tests, of course.
PR description
addresses #2041
This PR creates a utility method for parsing help input. It then uses that same logic in console-child.js. This is so that we use the same logic for parsing help input from both the command line and the development console (repl).
I also found out that yargs uses
console.error
for theshowHelp
method which we use to display general help in Truffle. This was causing a bug where general help would not print in the development console as the stderr was not "hooked up". So this PR also passes the "log" argument to this method to force it to useconsole.log
.Testing instructions
To test this, checkout this branch and run the development console. Enter "help" and you can see that the general help is printed to the screen.
Documentation
doc-change-required
label to this PR if documentation updates are required.Breaking changes and new features
breaking-change
andnew-feature
labels for the appropriate packages.