clap_nested_commands/
sync_commands.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#[macro_export]
macro_rules! generate_sync_commands {
    ($($module:ident),*) => (
        generate_sync_commands!(return_type = (); $($module),*);
    );
    (return_type = $return_type:ty; $($module:ident),*) => (
      paste::paste! {
        #[derive(Debug, Subcommand)]
        pub enum Commands {
            $(
                [<$module:camel>]($module::Command),
        )*
        }

        pub fn execute(cli_context: &CliContext, cmd: Command) -> $return_type {
            match cmd.command {
              $(
                Commands::[<$module:camel>](cmd) => $module::execute(cli_context, cmd),
              )*
            }
        }
      }
    );
}