Skip to content

Commit 7f84013

Browse files
committed
Improve cli consistency
1 parent e998f95 commit 7f84013

File tree

3 files changed

+20
-33
lines changed

3 files changed

+20
-33
lines changed

jscomp/bsb/bsb_arg.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ let stop_raise ~usage ~(error : error) (speclist : t) =
7979
Ext_buffer.output_buffer stdout b;
8080
exit 0
8181
| Unknown s ->
82-
b +> "unknown option: '";
82+
b +> "Unknown option \"";
8383
b +> s;
84-
b +> "'.\n"
84+
b +> "\".\n"
8585
| Missing s ->
86-
b +> "option '";
86+
b +> "Option \"";
8787
b +> s;
88-
b +> "' needs an argument.\n");
88+
b +> "\" needs an argument.\n");
8989
usage_b b ~usage speclist;
9090
bad_arg (Ext_buffer.contents b)
9191

jscomp/build_tests/cli_help/input.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ const cliHelp =
2222
"\n" +
2323
"Run `rescript <subcommand> -h` for subcommand help. Examples:\n" +
2424
" rescript build -h\n" +
25-
" rescript format -h\n" +
26-
"The default `rescript` is equivalent to `rescript build` subcommand\n" +
27-
"\n";
25+
" rescript format -h\n";
2826

2927
const buildHelp =
3028
"Usage: rescript build <options> -- <ninja_options>\n" +
@@ -105,7 +103,7 @@ out = child_process.spawnSync(`../../../rescript`, ["build", "-wtf"], {
105103
encoding: "utf8",
106104
cwd: __dirname,
107105
});
108-
assert.equal(out.stderr, "Error: unknown option: '-wtf'.\n" + buildHelp + "\n");
106+
assert.equal(out.stderr, 'Error: Unknown option "-wtf".\n' + buildHelp + "\n");
109107
assert.equal(out.status, 2);
110108

111109
// Shows cli help with --help arg
@@ -114,8 +112,7 @@ out = child_process.spawnSync(`../../../rescript`, ["--help"], {
114112
cwd: __dirname,
115113
});
116114
assert.equal(out.stdout, cliHelp);
117-
// FIXME: Should be 0
118-
assert.equal(out.status, 2);
115+
assert.equal(out.status, 0);
119116

120117
// Shows cli help with -h arg
121118
out = child_process.spawnSync(`../../../rescript`, ["-h"], {
@@ -138,19 +135,15 @@ out = child_process.spawnSync(`../../../rescript`, ["built"], {
138135
encoding: "utf8",
139136
cwd: __dirname,
140137
});
141-
// Should write to stderr instead ???
142-
assert.equal(out.stdout, cliHelp);
143-
// FIXME: Should show a warning that it's an unknown command
138+
assert.equal(out.stderr, `Error: Unknown command or flag "built".\n` + cliHelp);
144139
assert.equal(out.status, 2);
145140

146141
// Shows cli help with unknown args
147142
out = child_process.spawnSync(`../../../rescript`, ["-w"], {
148143
encoding: "utf8",
149144
cwd: __dirname,
150145
});
151-
// Should write to stderr instead ???
152-
assert.equal(out.stdout, cliHelp);
153-
// FIXME: Should show a warning that it's an unknown arg
146+
assert.equal(out.stderr, `Error: Unknown command or flag "-w".\n` + cliHelp);
154147
assert.equal(out.status, 2);
155148

156149
// Shows clean help with --help arg
@@ -174,7 +167,7 @@ out = child_process.spawnSync(`../../../rescript`, ["clean", "-wtf"], {
174167
encoding: "utf8",
175168
cwd: __dirname,
176169
});
177-
assert.equal(out.stderr, "Error: unknown option: '-wtf'.\n" + cleanHelp + "\n");
170+
assert.equal(out.stderr, 'Error: Unknown option "-wtf".\n' + cleanHelp + "\n");
178171
assert.equal(out.status, 2);
179172

180173
// Shows format help with --help arg

rescript

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ if (process.env.NINJA_ANSI_FORCED === undefined) {
6868
} else {
6969
dlog(`NINJA_ANSI_FORCED: "${process.env.NINJA_ANSI_FORCED}"`);
7070
}
71-
function help() {
72-
console.log(`Usage: rescript <options> <subcommand>
71+
72+
const helpMessage = `Usage: rescript <options> <subcommand>
7373
7474
\`rescript\` is equivalent to \`rescript build\`
7575
@@ -87,10 +87,7 @@ Subcommands:
8787
8888
Run \`rescript <subcommand> -h\` for subcommand help. Examples:
8989
rescript build -h
90-
rescript format -h
91-
The default \`rescript\` is equivalent to \`rescript build\` subcommand
92-
`);
93-
}
90+
rescript format -h`;
9491

9592
var isBuilding = false;
9693
function releaseBuild() {
@@ -545,13 +542,6 @@ Please pick a different one using the \`-ws [host:]port\` flag from bsb.`);
545542
bsc_exe
546543
);
547544
break;
548-
case "dump":
549-
require("./scripts/rescript_dump.js").main(
550-
process.argv.slice(3),
551-
rescript_exe,
552-
bsc_exe
553-
);
554-
break;
555545
case "convert":
556546
require("./scripts/rescript_convert.js").main(
557547
process.argv.slice(3),
@@ -561,16 +551,20 @@ Please pick a different one using the \`-ws [host:]port\` flag from bsb.`);
561551
break;
562552
case "-h":
563553
case "-help":
554+
case "--help":
564555
case "help":
565-
help();
556+
console.log(helpMessage);
566557
break;
567558
case "-v":
568559
case "-version":
560+
case "--version":
561+
case "version":
569562
console.log(require("./package.json").version);
570563
break;
571564
default:
572-
console.error(`Unknown subcommand or flags: ${maybeSubcommand}`);
573-
help();
565+
console.error(
566+
`Error: Unknown command or flag "${maybeSubcommand}".\n${helpMessage}`
567+
);
574568
process.exit(2);
575569
}
576570
}

0 commit comments

Comments
 (0)