Skip to content

Commit b8b680c

Browse files
committed
Finish cli help consistency improvements
1 parent 7f84013 commit b8b680c

File tree

4 files changed

+42
-24
lines changed

4 files changed

+42
-24
lines changed

jscomp/bsb_exe/rescript_main.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,6 @@ let () =
234234
start.pos_lnum Ext_json_parse.report_error e;
235235
exit 2
236236
| Bsb_arg.Bad s | Sys_error s ->
237-
Format.fprintf Format.err_formatter "@{<error>Error:@} %s@." s;
237+
Format.fprintf Format.err_formatter "@{<error>Error:@} %s" s;
238238
exit 2
239239
| e -> Ext_pervasives.reraise e

jscomp/build_tests/cli_help/input.js

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,23 @@ let out = child_process.spawnSync(`../../../rescript`, ["build", "--help"], {
7878
cwd: __dirname,
7979
});
8080
assert.equal(out.stdout, buildHelp);
81+
assert.equal(out.stderr, "");
8182
assert.equal(out.status, 0);
8283

83-
// Shows build help with --help arg
84+
// FIXME: Help works incorrectly in watch mode
8485
out = child_process.spawnSync(`../../../rescript`, ["build", "-w", "--help"], {
8586
encoding: "utf8",
8687
cwd: __dirname,
8788
});
8889
// FIXME: Shouldn't have "Start compiling" for help
8990
assert.equal(out.stdout, ">>>> Start compiling\n" + buildHelp);
91+
// FIXME: Don't run the watcher when showing help
92+
assert.match(
93+
out.stderr,
94+
new RegExp(
95+
"Uncaught Exception Error: ENOENT: no such file or directory, watch 'bsconfig.json'\n"
96+
)
97+
);
9098
// FIXME: Should be 0
9199
assert.equal(out.status, 1);
92100

@@ -96,14 +104,16 @@ out = child_process.spawnSync(`../../../rescript`, ["build", "-h"], {
96104
cwd: __dirname,
97105
});
98106
assert.equal(out.stdout, buildHelp);
107+
assert.equal(out.stderr, "");
99108
assert.equal(out.status, 0);
100109

101110
// Exits with build help with unknown arg
102111
out = child_process.spawnSync(`../../../rescript`, ["build", "-wtf"], {
103112
encoding: "utf8",
104113
cwd: __dirname,
105114
});
106-
assert.equal(out.stderr, 'Error: Unknown option "-wtf".\n' + buildHelp + "\n");
115+
assert.equal(out.stdout, "");
116+
assert.equal(out.stderr, 'Error: Unknown option "-wtf".\n' + buildHelp);
107117
assert.equal(out.status, 2);
108118

109119
// Shows cli help with --help arg
@@ -112,6 +122,7 @@ out = child_process.spawnSync(`../../../rescript`, ["--help"], {
112122
cwd: __dirname,
113123
});
114124
assert.equal(out.stdout, cliHelp);
125+
assert.equal(out.stderr, "");
115126
assert.equal(out.status, 0);
116127

117128
// Shows cli help with -h arg
@@ -120,6 +131,7 @@ out = child_process.spawnSync(`../../../rescript`, ["-h"], {
120131
cwd: __dirname,
121132
});
122133
assert.equal(out.stdout, cliHelp);
134+
assert.equal(out.stderr, "");
123135
assert.equal(out.status, 0);
124136

125137
// Shows cli help with help command
@@ -128,13 +140,15 @@ out = child_process.spawnSync(`../../../rescript`, ["help"], {
128140
cwd: __dirname,
129141
});
130142
assert.equal(out.stdout, cliHelp);
143+
assert.equal(out.stderr, "");
131144
assert.equal(out.status, 0);
132145

133146
// Shows cli help with unknown command
134147
out = child_process.spawnSync(`../../../rescript`, ["built"], {
135148
encoding: "utf8",
136149
cwd: __dirname,
137150
});
151+
assert.equal(out.stdout, "");
138152
assert.equal(out.stderr, `Error: Unknown command or flag "built".\n` + cliHelp);
139153
assert.equal(out.status, 2);
140154

@@ -143,6 +157,7 @@ out = child_process.spawnSync(`../../../rescript`, ["-w"], {
143157
encoding: "utf8",
144158
cwd: __dirname,
145159
});
160+
assert.equal(out.stdout, "");
146161
assert.equal(out.stderr, `Error: Unknown command or flag "-w".\n` + cliHelp);
147162
assert.equal(out.status, 2);
148163

@@ -152,6 +167,7 @@ out = child_process.spawnSync(`../../../rescript`, ["clean", "--help"], {
152167
cwd: __dirname,
153168
});
154169
assert.equal(out.stdout, cleanHelp);
170+
assert.equal(out.stderr, "");
155171
assert.equal(out.status, 0);
156172

157173
// Shows clean help with -h arg
@@ -160,66 +176,68 @@ out = child_process.spawnSync(`../../../rescript`, ["clean", "-h"], {
160176
cwd: __dirname,
161177
});
162178
assert.equal(out.stdout, cleanHelp);
179+
assert.equal(out.stderr, "");
163180
assert.equal(out.status, 0);
164181

165182
// Exits with clean help with unknown arg
166183
out = child_process.spawnSync(`../../../rescript`, ["clean", "-wtf"], {
167184
encoding: "utf8",
168185
cwd: __dirname,
169186
});
170-
assert.equal(out.stderr, 'Error: Unknown option "-wtf".\n' + cleanHelp + "\n");
187+
assert.equal(out.stdout, "");
188+
assert.equal(out.stderr, 'Error: Unknown option "-wtf".\n' + cleanHelp);
171189
assert.equal(out.status, 2);
172190

173191
// Shows format help with --help arg
174192
out = child_process.spawnSync(`../../../rescript`, ["format", "--help"], {
175193
encoding: "utf8",
176194
cwd: __dirname,
177195
});
178-
// Note: it writes to stderr
179-
assert.equal(out.stderr, formatHelp);
196+
assert.equal(out.stdout, formatHelp);
197+
assert.equal(out.stderr, "");
180198
assert.equal(out.status, 0);
181199

182200
// Shows format help with -h arg
183201
out = child_process.spawnSync(`../../../rescript`, ["format", "-h"], {
184202
encoding: "utf8",
185203
cwd: __dirname,
186204
});
187-
// Note: it writes to stderr
188-
assert.equal(out.stderr, formatHelp);
205+
assert.equal(out.stdout, formatHelp);
206+
assert.equal(out.stderr, "");
189207
assert.equal(out.status, 0);
190208

191209
// Shows convert help with --help arg
192210
out = child_process.spawnSync(`../../../rescript`, ["convert", "--help"], {
193211
encoding: "utf8",
194212
cwd: __dirname,
195213
});
196-
// Note: it writes to stderr
197-
assert.equal(out.stderr, convertHelp);
214+
assert.equal(out.stdout, convertHelp);
215+
assert.equal(out.stderr, "");
198216
assert.equal(out.status, 0);
199217

200218
// Shows convert help with -h arg
201219
out = child_process.spawnSync(`../../../rescript`, ["convert", "-h"], {
202220
encoding: "utf8",
203221
cwd: __dirname,
204222
});
205-
// Note: it writes to stderr
206-
assert.equal(out.stderr, convertHelp);
223+
assert.equal(out.stdout, convertHelp);
224+
assert.equal(out.stderr, "");
207225
assert.equal(out.status, 0);
208226

209227
// Shows dump help with --help arg
210228
out = child_process.spawnSync(`../../../rescript`, ["dump", "--help"], {
211229
encoding: "utf8",
212230
cwd: __dirname,
213231
});
214-
// Note: it writes to stderr
215-
assert.equal(out.stderr, dumpHelp);
232+
assert.equal(out.stdout, dumpHelp);
233+
assert.equal(out.stderr, "");
216234
assert.equal(out.status, 0);
217235

218236
// Shows dump help with -h arg
219237
out = child_process.spawnSync(`../../../rescript`, ["dump", "-h"], {
220238
encoding: "utf8",
221239
cwd: __dirname,
222240
});
223-
// Note: it writes to stderr
224-
assert.equal(out.stderr, dumpHelp);
241+
assert.equal(out.stdout, dumpHelp);
242+
assert.equal(out.stderr, "");
225243
assert.equal(out.status, 0);

jscomp/ext/bsc_args.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,16 @@ let stop_raise ~usage ~(error : error) (speclist : t) =
8686
Ext_buffer.output_buffer stdout b;
8787
exit 0
8888
| Unknown s ->
89-
b +> "unknown option: '";
89+
b +> "Unknown option \"";
9090
b +> s;
91-
b +> "'.\n"
91+
b +> "\".\n"
9292
| Missing s ->
93-
b +> "option '";
93+
b +> "Option \"";
9494
b +> s;
95-
b +> "' needs an argument.\n");
95+
b +> "\" needs an argument.\n");
9696
usage_b b ~usage speclist;
9797
bad_arg (Ext_buffer.contents b)
98-
98+
9999
let parse_exn ~usage ~argv ?(start = 1) ?(finish = Array.length argv)
100100
(speclist : t) (anonfun : rev_args:string list -> unit) =
101101
let current = ref start in

scripts/rescript_arg.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ function stop_raise(usage, error, specs) {
8484
case "Unknown":
8585
if (["-help", "--help", "-h"].includes(error.data)) {
8686
usage_b(b, usage, specs);
87-
process.stderr.write(b.val);
87+
process.stdout.write(b.val);
8888
process.exit(0);
8989
} else {
90-
b.add("unknown option: '").add(error.data).add("'.\n");
90+
b.add(`Unknown option "${error.data}".\n'`);
9191
}
9292
case "Missing":
93-
b.add("option '").add(error.data).add("' needs an argument.\n");
93+
b.add(`Option "${error.data}" needs an argument.\n'`);
9494
}
9595
usage_b(b, usage, specs);
9696
bad_arg(b.val);

0 commit comments

Comments
 (0)