# HG changeset patch # User Arseniy Alekseyev # Date 2024-12-13 16:19:29 # Node ID 021c1b1671e560d298e116631c07374986c32396 # Parent 92c6c8ab6f94b3d9e9b4d095737f5e57e805e4dc rhg: consistently use the command name given in clap::command!(<...>) macro Before this patch there are 2 things the user controls: 1. the module/command name, specified in subcommand! macro 2. the command name, specified in clap::command! macro If these are out of sync, we get no compile error or a clear runtime error, but instead a confusing behavior where command line parser parses one thing, but running it doesn't work. This commit makes the clap::command! macro the sole authority determining the command name, so we don't have to worry about this weird behavior any more. It also makes it easy to validate agreement between (1) and (2) if we want it, but I didn't add the check because I'm not sure people necessarily want it. diff --git a/rust/rhg/src/main.rs b/rust/rhg/src/main.rs --- a/rust/rhg/src/main.rs +++ b/rust/rhg/src/main.rs @@ -545,13 +545,15 @@ struct SubCommand { } macro_rules! subcommand { - ($command: ident) => { + ($command: ident) => {{ + let args = commands::$command::args(); + let name = args.get_name().to_string(); SubCommand { - args: commands::$command::args(), + args, run: commands::$command::run, - name: stringify!($command).to_string(), + name, } - }; + }}; } fn subcommands() -> Vec { vec![