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 diff --git a/rewatch/src/cli.rs b/rewatch/src/cli.rs index 0870f603ea..b28781ddc8 100644 --- a/rewatch/src/cli.rs +++ b/rewatch/src/cli.rs @@ -22,6 +22,9 @@ pub enum FileExtension { #[derive(Parser, Debug)] #[command(version)] #[command(args_conflicts_with_subcommands = true)] +#[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 @@ -35,10 +38,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 +164,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..41228e4685 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) => arg.starts_with("-") && !global_flags.contains(&arg.as_str()), + None => true, + }; + + if needs_default_arg { + args.insert(1, "build".to_string()); + } +}