Skip to content

Commit 5ee35e9

Browse files
committed
add comments
1 parent f638944 commit 5ee35e9

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

rewatch/src/cli.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ pub enum FileExtension {
2020

2121
/// ReScript - Fast, Simple, Fully Typed JavaScript from the Future
2222
#[derive(Parser, Debug)]
23+
// The shipped binary is `rescript.exe` everywhere, but users invoke it as `rescript` (e.g.
24+
// via `npm run rescript`). Without forcing `bin_name`, clap would print `rescript.exe` in help,
25+
// which leaks the packaging detail into the CLI UX.
2326
#[command(name = "rescript", bin_name = "rescript")]
2427
#[command(version)]
2528
#[command(

rewatch/src/main.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ fn get_lock(folder: &str) -> lock::Lock {
116116
}
117117

118118
fn parse_cli(raw_args: Vec<OsString>) -> Result<cli::Cli, clap::Error> {
119+
// Clap's builder API cannot express "build" as an implicit default subcommand without also
120+
// polluting the top-level help output. To keep help focused while still honoring "rescript"
121+
// invocations that omit a command, we first attempt the canonical parse and only synthesize a
122+
// `build` subcommand when clap tells us the invocation failed because no subcommand (or a
123+
// positional that maps to one) was provided.
119124
match cli::Cli::try_parse_from(&raw_args) {
120125
Ok(cli) => Ok(cli),
121126
Err(err) => {
@@ -185,6 +190,10 @@ fn is_known_subcommand(arg: &OsString) -> bool {
185190
}
186191

187192
fn build_default_args(raw_args: &[OsString]) -> Vec<OsString> {
193+
// Preserve clap's global flag handling semantics by keeping `-v/-q/-h/-V` in front of the
194+
// inserted `build` token while leaving the rest of the argv untouched. This mirrors clap's own
195+
// precedence rules so the second parse sees an argument layout it would have produced if the
196+
// user had typed `rescript build …` directly.
188197
let mut result = Vec::with_capacity(raw_args.len() + 1);
189198
if raw_args.is_empty() {
190199
return vec![OsString::from("build")];

0 commit comments

Comments
 (0)