-
Notifications
You must be signed in to change notification settings - Fork 79
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
Improve elm-test.js #465
Improve elm-test.js #465
Conversation
It used not to show, but just out of coincidence.
Also make the help text fit in a default small terminal window.
@harrysarson I think I’ve addressed all comments now! |
lib/Flags.js
Outdated
// Or the next argument: `--flag value`. | ||
const getValue = (fallback /*: string */) /*: string */ => { | ||
if (match === null) { | ||
index++; |
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 do not like that we have a for loop and then a closure that mutates the index variable. My lunch break is almost over though and I haven't come up with a more constructive suggestion yet. Let me go and think about this.
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.
We talked about this on discord. @lydell is going to look into some alternatives to minimist
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.
Just a couple of nits. I like the flag parsing with commander and I think you have done a nice job of hacking around/dealing with its shortcomings such that is is clear what is going on.
Have you tested these changes against any project test suites?
Co-authored-by: Harry Sarson <[email protected]>
I’m not sure what to test? |
I was just thinking
as a sanity check. |
Ok! I tried that at work and in the elm-review repo and it worked fine. |
Regression from #465. Before: ``` ❯ ../bin/elm-test install truqu/elm-md5 I am having trouble with this argument: t It is supposed to be a <package> value, like one of these: elm/html elm/http elm/svg elm/time ``` After: ``` ❯ ../bin/elm-test install truqu/elm-md5 Here is my plan: Add: truqu/elm-md5 1.1.0 zwilias/elm-utf-tools 2.0.1 Would you like me to update your elm.json accordingly? [Y/n]: Success! ``` This happened because I thought the first argument of the `.action` callback is always an array. Wrong! The signature depends on the `.command` syntax provided: ```js program .command('name <one> <two> [three] [rest...]') .action((one: string, two: string, three: string | undefined, rest: Array<string>, cmd: Command) => { // Do stuff }); ``` For the install command we have: ```js program .command('install <package>') .action((packageName: string, cmd: Command) => {}) ``` Before we tried to destructure the first argument (thinking it was an array), so we only got the first letter of the package name. Unfortunately our test suite doesn’t catch this.
Fixes #211
Addresses #442 (comment)
This PR makes a bunch of improvements to elm-test.js:
Properly validate CLI arguments:
elm-test.js is now 100% definitions, except the last line which is
main();
to kick things off. Previously, it was difficult to understand in what order things executed. There was some top-level code, a bunch of function definitions, some more top-level code, more functions, and so on. Now, you can follow the call stack frommain()
. Also, this means that there are way fewer global variables – functions now get passed what they depend on.Use async/await where it helps (in preparation for merge conflicts with Moving to async/await: lib/Runner.js #464 – it should be possible to just pick this PR’s code for every conflict in elm-test.js).
Improved help message. Also, add some aliases, such as
-h
, for showing help. I find it super annoying when CLI tools make it difficult to find the help – which is the key to all other commands and flags.Various cleanups.
Help before:
Intermediate help (outdated):
commander help: