-
Notifications
You must be signed in to change notification settings - Fork 455
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
Fix compile status with help command #6439
Fix compile status with help command #6439
Conversation
const isDefinitelyBuild = | ||
maybeSubcommand === undefined || | ||
(maybeSubcommand === "build" && process_argv.length === 3); | ||
|
||
if (isDefinitelyBuild) { | ||
logStartCompiling(); | ||
delegateCommand(process_argv.slice(2), logFinishCompiling); | ||
} 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.
A little bit hacky, but I think better, than nothing. Ideally, to move all the args parsing logic on the js side in one place.
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.
https://nodejs.org/api/util.html#utilparseargsconfig will be useful if we accept #6429
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 was actually thinking of using minimist
, but https://github.com/pkgjs/parseargs also looks good.
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 we are more tolerant of external dependencies we can even import more, like clipanion 😂
@cknitt you've been reviewing changes here before, up for reviewing this 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.
Thanks for adding those tests, this is great! 👍
Thanks for feedback, I'll return back with the improvements |
Should we use status |
b8b680c
to
514b317
Compare
@cknitt It's ready for re review |
b +> "unknown option: '"; | ||
b +> "Unknown option \""; | ||
b +> s; | ||
b +> "'.\n" | ||
b +> "\".\n" | ||
| Missing s -> | ||
b +> "option '"; | ||
b +> "Option \""; | ||
b +> s; | ||
b +> "' needs an argument.\n"); |
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.
Actually, the code is not used in my case. I've just decided to make it consistent with bsb_arg.ml.
break; | ||
case "-h": | ||
case "-help": | ||
case "--help": |
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.
Added --help
here
case "--version": | ||
case "version": |
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.
Added --version
and version
here
console.error( | ||
`Error: Unknown command or flag "${maybeSubcommand}".\n${helpMessage}` | ||
); |
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.
Now everything will come to stderr
. Before helpMessage was shown in stdout
while Unknown command or flag
in stdout. That's also the reason why I have both stdout
and stderr
check in the tests.
// FIXME: Help works incorrectly in watch mode | ||
out = child_process.spawnSync(`../../../rescript`, ["build", "-w", "--help"], { | ||
encoding: "utf8", | ||
cwd: __dirname, | ||
}); | ||
// FIXME: Shouldn't have "Start compiling" for help | ||
assert.equal(out.stdout, ">>>> Start compiling\n" + buildHelp); | ||
// FIXME: Don't run the watcher when showing help | ||
assert.match( | ||
out.stderr, | ||
new RegExp( | ||
"Uncaught Exception Error: ENOENT: no such file or directory, watch 'bsconfig.json'\n" | ||
) | ||
); | ||
// FIXME: Should be 0 | ||
assert.equal(out.status, 1); |
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'll be only possible to fix by moving the args parsing logic in one place. I want to do it when I have more free time.
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.
What about the other three FIXMEs above? Also something for later?
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.
Yeah, they are all caused by one problem
jscomp/build_tests/cli_help/input.js
Outdated
"\n" + | ||
"`rescript build` builds the project with dependencies\n" + | ||
"\n" + | ||
"`rescript -- -h` for Ninja options (internal usage only; unstable)\n" + |
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.
Should be rescript build -- -h
.
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.
Good to have tests 😁 Fixed 👌
// FIXME: Help works incorrectly in watch mode | ||
out = child_process.spawnSync(`../../../rescript`, ["build", "-w", "--help"], { | ||
encoding: "utf8", | ||
cwd: __dirname, | ||
}); | ||
// FIXME: Shouldn't have "Start compiling" for help | ||
assert.equal(out.stdout, ">>>> Start compiling\n" + buildHelp); | ||
// FIXME: Don't run the watcher when showing help | ||
assert.match( | ||
out.stderr, | ||
new RegExp( | ||
"Uncaught Exception Error: ENOENT: no such file or directory, watch 'bsconfig.json'\n" | ||
) | ||
); | ||
// FIXME: Should be 0 | ||
assert.equal(out.status, 1); |
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.
What about the other three FIXMEs above? Also something for later?
@DZakh Just wanted to merge this for rc.5, but there are conflicts, could you resolve them? |
I'll fix on Monday |
ab20cdb
to
f1d4059
Compare
Fixes: #6435 (comment) (only the comment)