Show More
@@ -536,39 +536,51 mod commands { | |||||
536 | pub mod status; |
|
536 | pub mod status; | |
537 | } |
|
537 | } | |
538 |
|
538 | |||
539 | macro_rules! subcommands { |
|
539 | pub type RunFn = fn(&CliInvocation) -> Result<(), CommandError>; | |
540 | ($( $command: ident )+) => { |
|
|||
541 |
|
||||
542 | fn add_subcommand_args(app: clap::Command) -> clap::Command { |
|
|||
543 | app |
|
|||
544 | $( |
|
|||
545 | .subcommand(commands::$command::args()) |
|
|||
546 | )+ |
|
|||
547 | } |
|
|||
548 |
|
540 | |||
549 | pub type RunFn = fn(&CliInvocation) -> Result<(), CommandError>; |
|
541 | struct SubCommand { | |
|
542 | run: RunFn, | |||
|
543 | args: clap::Command, | |||
|
544 | name: String, | |||
|
545 | } | |||
550 |
|
546 | |||
551 | fn subcommand_run_fn(name: &str) -> Option<RunFn> { |
|
547 | macro_rules! subcommand { | |
552 | match name { |
|
548 | ($command: ident) => { | |
553 | $( |
|
549 | SubCommand { | |
554 |
|
|
550 | args: commands::$command::args(), | |
555 | )+ |
|
551 | run: commands::$command::run, | |
556 | _ => None, |
|
552 | name: stringify!($command).to_string(), | |
557 | } |
|
|||
558 | } |
|
553 | } | |
559 | }; |
|
554 | }; | |
560 | } |
|
555 | } | |
|
556 | fn subcommands() -> Vec<SubCommand> { | |||
|
557 | vec![ | |||
|
558 | subcommand!(cat), | |||
|
559 | subcommand!(debugdata), | |||
|
560 | subcommand!(debugrequirements), | |||
|
561 | subcommand!(debugignorerhg), | |||
|
562 | subcommand!(debugrhgsparse), | |||
|
563 | subcommand!(files), | |||
|
564 | subcommand!(root), | |||
|
565 | subcommand!(config), | |||
|
566 | subcommand!(status), | |||
|
567 | ] | |||
|
568 | } | |||
561 |
|
569 | |||
562 | subcommands! { |
|
570 | fn add_subcommand_args(mut app: clap::Command) -> clap::Command { | |
563 | cat |
|
571 | for s in subcommands() { | |
564 | debugdata |
|
572 | app = app.subcommand(s.args) | |
565 | debugrequirements |
|
573 | } | |
566 | debugignorerhg |
|
574 | app | |
567 | debugrhgsparse |
|
575 | } | |
568 | files |
|
576 | ||
569 | root |
|
577 | fn subcommand_run_fn(name: &str) -> Option<RunFn> { | |
570 | config |
|
578 | for s in subcommands() { | |
571 | status |
|
579 | if s.name == name { | |
|
580 | return Some(s.run); | |||
|
581 | } | |||
|
582 | } | |||
|
583 | None | |||
572 | } |
|
584 | } | |
573 |
|
585 | |||
574 | pub struct CliInvocation<'a> { |
|
586 | pub struct CliInvocation<'a> { |
General Comments 0
You need to be logged in to leave comments.
Login now