Skip to content
Snippets Groups Projects
Commit 2d52ae3c authored by Arseniy Alekseyev's avatar Arseniy Alekseyev
Browse files

rhg: simplify SubCommand macro a bit more

Remove the `name` field from the `SubCommand` record,
make it an accessor instead, which makes the record smaller,
and the macro smaller.
parent b89c934e
No related branches found
No related tags found
2 merge requests!1292Draft: 7.0rc preparation,!1138rust-ignore: construct regex Hir object directly, avoiding large regex string
Pipeline #96063 passed
......@@ -543,8 +543,7 @@
struct SubCommand {
run: RunFn,
args: clap::Command,
name: String,
/// used for reporting collision
/// used for reporting name collisions
origin: String,
}
......@@ -548,5 +547,11 @@
origin: String,
}
impl SubCommand {
fn name(&self) -> String {
self.args.get_name().to_string()
}
}
macro_rules! subcommand {
($command: ident) => {{
......@@ -551,6 +556,3 @@
macro_rules! subcommand {
($command: ident) => {{
let args = commands::$command::args();
let name = args.get_name().to_string();
let origin = stringify!($command).to_string();
SubCommand {
......@@ -556,3 +558,3 @@
SubCommand {
args,
args: commands::$command::args(),
run: commands::$command::run,
......@@ -558,6 +560,5 @@
run: commands::$command::run,
name,
origin,
origin: stringify!($command).to_string(),
}
}};
}
......@@ -577,7 +578,7 @@
}
pub fn add(&mut self, subcommand: SubCommand) {
let name = subcommand.name;
let name = subcommand.name();
if let Some((origin_old, _)) = self
.run
.insert(name.clone(), (subcommand.origin.clone(), subcommand.run))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment