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