-
Notifications
You must be signed in to change notification settings - Fork 471
Rewatch cli help: do not show build command options in the root help #7715
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
Conversation
rescript
@rescript/darwin-arm64
@rescript/darwin-x64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
This is not 100% correct yet as long as we have the |
dbe5153
to
f7889aa
Compare
@codex review |
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
rewatch/src/main.rs
Outdated
fn should_default_to_build(err: &clap::Error, args: &[String]) -> bool { | ||
match err.kind() { | ||
ErrorKind::MissingSubcommand | ErrorKind::DisplayHelpOnMissingArgumentOrSubcommand => true, | ||
ErrorKind::UnknownArgument | ErrorKind::InvalidSubcommand => { | ||
args.iter().skip(1).any(|arg| !is_global_flag(arg)) | ||
} |
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.
[P1] Avoid defaulting to build when a subcommand was supplied
The fallback parsing in should_default_to_build
treats any UnknownArgument
or InvalidSubcommand
as an omitted subcommand as long as a non‑global token exists. When a user explicitly runs another subcommand but mistypes an option that only build
understands, the second parse injects build
and succeeds. For example, rescript watch --no-timing
(an invalid option for watch
) is reinterpreted as rescript build watch --no-timing
, so the tool performs a one‑off build of the watch
folder and exits instead of starting the watcher. That silent command switch regresses error reporting and will surprise users trying to run watch
/clean
/format
. The fallback should only fire when no subcommand token is present, not when an explicit subcommand failed to parse.
Useful? React with 👍 / 👎.
@codex review |
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
@codex review |
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
rewatch/src/main.rs
Outdated
if should_default_to_build(&err, &raw_args) { | ||
let mut fallback_args = raw_args.clone(); | ||
let insert_at = index_after_global_flags(&fallback_args); | ||
fallback_args.insert(insert_at, OsString::from("build")); |
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.
[P1] Default build fallback rejects global flags after folder paths
When the user omits an explicit subcommand, parse_cli
inserts the implicit build
token after only the leading global flags. Global flags that appear after the folder argument (e.g. rescript my-project -v
or rescript ./ --quiet
) are left trailing the newly inserted build
token, so clap parses them as arguments to the build
subcommand and reports UnknownArgument
. The pre‑existing CLI accepted these invocations because there was no subcommand and global flags could be positioned after the folder. This regression will break scripts that pass -v/--quiet
after the path. Consider collecting global flags regardless of position or reordering them ahead of the injected build
command before reparsing.
Useful? React with 👍 / 👎.
@codex review |
Codex Review: Didn't find any major issues. What shall we delve into next? ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. |
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 haven't used Clap much, so I'm not the best person to review this.
As we do these days, I chatted with an LLM about it. Overall, this adds complexity, and all the juggling with Clap makes me wonder if we should keep using it. If Clap does not support default subcommands, it might not be the right fit.
If we do intend to keep it, I'd like to see more architectural notes. This is a trade-off and we should be upfront about that. Future Rustacean contributors might frown on this, so we should acknowledge the potential heresy.
From what I can see, clap seems to be the most commonly used and feature rich command-line argument parser in the Rust world. Not to keen on swapping it out for something else, especially at this point of the release cycle.
Right, I'll add comments for that. |
rewatch/src/main.rs
Outdated
} | ||
} | ||
|
||
fn parse_cli(raw_args: Vec<OsString>) -> Result<cli::Cli, clap::Error> { |
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.
Makes me wonder if we can check if the first argument is any of the verbs, if not prepend the vector with build
.
That way we avoid the double parse in the error case.
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.
That's what I had in the beginning, and it had other issues.
See the previous codex reviews, it took quite a few attempts until everything worked correctly.
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.
While I still think this is not ideal, the pragmatic thing is to move on now!
Rewatch’s CLI now keeps the top-level help focused: it no longer floods
rescript --help
with all build options. Instead, users learn via the after-help note that build is the default subcommand and can dig deeper with rescript help build:Unfortunately, clap does not support default subcommands out of the box, so this gets a bit tricky. We "double-parse" the arguments as follows:
Cli::try_parse_from(&args)
exactly as clap would. If it succeeds, we’re done.build
), we clone the argument list, insert the implicit "build" at the right spot (after any global flags), and calltry_parse_from
again.build
and keep going.We also add targeted unit tests that exercise defaulting, folder shortcuts, global-flag ordering, and help/version passthrough to guard the new behavior.