From 5b063ef309a8a963e5421eabb5ac769e2a98bf72 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Fri, 25 Jul 2025 08:30:49 +0200 Subject: [PATCH 1/4] Rewatch cli help: do not show build command options in the root help --- rewatch/src/cli.rs | 8 +++----- rewatch/src/main.rs | 25 +++++++++++++++++++++---- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/rewatch/src/cli.rs b/rewatch/src/cli.rs index 0870f603ea..da50ec2162 100644 --- a/rewatch/src/cli.rs +++ b/rewatch/src/cli.rs @@ -22,6 +22,7 @@ pub enum FileExtension { #[derive(Parser, Debug)] #[command(version)] #[command(args_conflicts_with_subcommands = true)] +#[command(after_help = "NOTE: If no subcommand is provided, `build` is run by default.")] pub struct Cli { /// Verbosity: /// -v -> Debug @@ -35,10 +36,7 @@ pub struct Cli { /// The command to run. If not provided it will default to build. #[command(subcommand)] - pub command: Option, - - #[command(flatten)] - pub build_args: BuildArgs, + pub command: Command, } #[derive(Args, Debug, Clone)] @@ -164,7 +162,7 @@ impl From for WatchArgs { #[derive(Subcommand, Clone, Debug)] pub enum Command { - /// Build the project + /// Build the project (default command) Build(BuildArgs), /// Build, then start a watcher Watch(WatchArgs), diff --git a/rewatch/src/main.rs b/rewatch/src/main.rs index 7ae9ae0884..7ecc5e535a 100644 --- a/rewatch/src/main.rs +++ b/rewatch/src/main.rs @@ -1,14 +1,17 @@ use anyhow::Result; use clap::Parser; use log::LevelFilter; -use std::{io::Write, path::Path}; +use std::{env, io::Write, path::Path}; use rescript::{build, cli, cmd, format, lock, watcher}; fn main() -> Result<()> { - let args = cli::Cli::parse(); + let mut args: Vec = env::args().collect(); + handle_default_arg(&mut args); - let log_level_filter = args.verbose.log_level_filter(); + let cli = cli::Cli::parse_from(args); + + let log_level_filter = cli.verbose.log_level_filter(); env_logger::Builder::new() .format(|buf, record| writeln!(buf, "{}:\n{}", record.level(), record.args())) @@ -16,7 +19,7 @@ fn main() -> Result<()> { .target(env_logger::fmt::Target::Stdout) .init(); - let mut command = args.command.unwrap_or(cli::Command::Build(args.build_args)); + let mut command = cli.command; if let cli::Command::Build(build_args) = &command { if build_args.watch { @@ -109,3 +112,17 @@ fn get_lock(folder: &str) -> lock::Lock { acquired_lock => acquired_lock, } } + +fn handle_default_arg(args: &mut Vec) { + let first_arg = args.get(1); + let global_flags = ["-h", "--help", "-V", "--version"]; + + let needs_default_arg = match first_arg { + Some(arg) if !arg.starts_with("-") || global_flags.contains(&arg.as_str()) => false, + _ => true, + }; + + if needs_default_arg { + args.insert(1, "build".to_string()); + } +} From d2d4acb44f87a37cb88479abe86a8f9b7e2a2f35 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Fri, 25 Jul 2025 11:16:58 +0200 Subject: [PATCH 2/4] Satisfy clippy --- rewatch/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rewatch/src/main.rs b/rewatch/src/main.rs index 7ecc5e535a..41228e4685 100644 --- a/rewatch/src/main.rs +++ b/rewatch/src/main.rs @@ -118,8 +118,8 @@ fn handle_default_arg(args: &mut Vec) { let global_flags = ["-h", "--help", "-V", "--version"]; let needs_default_arg = match first_arg { - Some(arg) if !arg.starts_with("-") || global_flags.contains(&arg.as_str()) => false, - _ => true, + Some(arg) => arg.starts_with("-") && !global_flags.contains(&arg.as_str()), + None => true, }; if needs_default_arg { From f92128b206a5331dbf16988897a5ae594f15569f Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Fri, 25 Jul 2025 11:18:08 +0200 Subject: [PATCH 3/4] CHANGELOG # Conflicts: # CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58bd186eef..07cbfaaa27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ - Polish arity mismatch error message a bit. https://github.com/rescript-lang/rescript/pull/7709 - Suggest related functions with the expected arity in errors when it makes sense. https://github.com/rescript-lang/rescript/pull/7712 - Improve error when a constructor expects an inline record. https://github.com/rescript-lang/rescript/pull/7713 +- Rewatch cli: do not show build command options in the root help. https://github.com/rescript-lang/rescript/pull/7715 #### :house: Internal From dbe51535821320bb75c576f861018313d07e6379 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Fri, 25 Jul 2025 13:36:53 +0200 Subject: [PATCH 4/4] Text + Formatting --- rewatch/src/cli.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rewatch/src/cli.rs b/rewatch/src/cli.rs index da50ec2162..b28781ddc8 100644 --- a/rewatch/src/cli.rs +++ b/rewatch/src/cli.rs @@ -22,7 +22,9 @@ pub enum FileExtension { #[derive(Parser, Debug)] #[command(version)] #[command(args_conflicts_with_subcommands = true)] -#[command(after_help = "NOTE: If no subcommand is provided, `build` is run by default.")] +#[command( + after_help = "Note: If no command is provided, the build command is run by default. See `rescript help build` for more information." +)] pub struct Cli { /// Verbosity: /// -v -> Debug