rust/rhg/src/main.rs
author Simon Sapin <simon.sapin@octobus.net>
Mon, 15 Feb 2021 20:05:32 +0100
changeset 46631 80840b651721
parent 46630 21d3b40b4c0e
child 46632 5ce2aa7c2ad5
permissions -rw-r--r--
rhg: Group values passed to every sub-command into a struct The set of which values this is is evidently not stable yet, so this will make changes easier. Also it is growing, and the function signatures are getting out hand. Differential Revision: https://phab.mercurial-scm.org/D10003
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
45536
b1cea0dc9db0 rhg: Add debug timing
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45535
diff changeset
     1
extern crate log;
46631
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
     2
use crate::ui::Ui;
45051
18f8d3b31baa rhg: add a limited `rhg root` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45050
diff changeset
     3
use clap::App;
18f8d3b31baa rhg: add a limited `rhg root` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45050
diff changeset
     4
use clap::AppSettings;
46555
d8730ff51d5a rhg: Add support for -R and --repository command-line arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46554
diff changeset
     5
use clap::Arg;
45535
f17caf8f3fef rhg: add a limited `rhg debugdata` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45451
diff changeset
     6
use clap::ArgMatches;
46513
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 45938
diff changeset
     7
use format_bytes::format_bytes;
46631
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
     8
use hg::config::Config;
46555
d8730ff51d5a rhg: Add support for -R and --repository command-line arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46554
diff changeset
     9
use std::path::Path;
45051
18f8d3b31baa rhg: add a limited `rhg root` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45050
diff changeset
    10
45002
bacf6c7ef01b rhg: add Command trait for subcommands implemented by rhg
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45001
diff changeset
    11
mod error;
45001
cf04f62d1579 rhg: add rhg crate
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
    12
mod exitcode;
45050
513b3ef277a3 rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45002
diff changeset
    13
mod ui;
45535
f17caf8f3fef rhg: add a limited `rhg debugdata` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45451
diff changeset
    14
use error::CommandError;
45001
cf04f62d1579 rhg: add rhg crate
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
    15
46555
d8730ff51d5a rhg: Add support for -R and --repository command-line arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46554
diff changeset
    16
fn add_global_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
d8730ff51d5a rhg: Add support for -R and --repository command-line arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46554
diff changeset
    17
    app.arg(
d8730ff51d5a rhg: Add support for -R and --repository command-line arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46554
diff changeset
    18
        Arg::with_name("repository")
d8730ff51d5a rhg: Add support for -R and --repository command-line arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46554
diff changeset
    19
            .help("repository root directory")
d8730ff51d5a rhg: Add support for -R and --repository command-line arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46554
diff changeset
    20
            .short("-R")
d8730ff51d5a rhg: Add support for -R and --repository command-line arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46554
diff changeset
    21
            .long("--repository")
d8730ff51d5a rhg: Add support for -R and --repository command-line arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46554
diff changeset
    22
            .value_name("REPO")
d8730ff51d5a rhg: Add support for -R and --repository command-line arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46554
diff changeset
    23
            .takes_value(true),
d8730ff51d5a rhg: Add support for -R and --repository command-line arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46554
diff changeset
    24
    )
46556
2e5dd18d6dc3 rhg: Add support for --config CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46555
diff changeset
    25
    .arg(
2e5dd18d6dc3 rhg: Add support for --config CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46555
diff changeset
    26
        Arg::with_name("config")
2e5dd18d6dc3 rhg: Add support for --config CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46555
diff changeset
    27
            .help("set/override config option (use 'section.name=value')")
2e5dd18d6dc3 rhg: Add support for --config CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46555
diff changeset
    28
            .long("--config")
2e5dd18d6dc3 rhg: Add support for --config CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46555
diff changeset
    29
            .value_name("CONFIG")
2e5dd18d6dc3 rhg: Add support for --config CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46555
diff changeset
    30
            .takes_value(true)
2e5dd18d6dc3 rhg: Add support for --config CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46555
diff changeset
    31
            // Ok: `--config section.key1=val --config section.key2=val2`
2e5dd18d6dc3 rhg: Add support for --config CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46555
diff changeset
    32
            .multiple(true)
2e5dd18d6dc3 rhg: Add support for --config CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46555
diff changeset
    33
            // Not ok: `--config section.key1=val section.key2=val2`
2e5dd18d6dc3 rhg: Add support for --config CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46555
diff changeset
    34
            .number_of_values(1),
2e5dd18d6dc3 rhg: Add support for --config CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46555
diff changeset
    35
    )
46555
d8730ff51d5a rhg: Add support for -R and --repository command-line arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46554
diff changeset
    36
}
d8730ff51d5a rhg: Add support for -R and --repository command-line arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46554
diff changeset
    37
46630
21d3b40b4c0e rhg: Remove error message on unsupported CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46557
diff changeset
    38
fn main_with_result(ui: &ui::Ui) -> Result<(), CommandError> {
45536
b1cea0dc9db0 rhg: Add debug timing
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45535
diff changeset
    39
    env_logger::init();
45535
f17caf8f3fef rhg: add a limited `rhg debugdata` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45451
diff changeset
    40
    let app = App::new("rhg")
45051
18f8d3b31baa rhg: add a limited `rhg root` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45050
diff changeset
    41
        .setting(AppSettings::AllowInvalidUtf8)
18f8d3b31baa rhg: add a limited `rhg root` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45050
diff changeset
    42
        .setting(AppSettings::SubcommandRequired)
18f8d3b31baa rhg: add a limited `rhg root` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45050
diff changeset
    43
        .setting(AppSettings::VersionlessSubcommands)
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
    44
        .version("0.0.1");
46555
d8730ff51d5a rhg: Add support for -R and --repository command-line arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46554
diff changeset
    45
    let app = add_global_args(app);
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
    46
    let app = add_subcommand_args(app);
45051
18f8d3b31baa rhg: add a limited `rhg root` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45050
diff changeset
    47
46630
21d3b40b4c0e rhg: Remove error message on unsupported CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46557
diff changeset
    48
    let matches = app.clone().get_matches_safe()?;
46555
d8730ff51d5a rhg: Add support for -R and --repository command-line arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46554
diff changeset
    49
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
    50
    let (subcommand_name, subcommand_matches) = matches.subcommand();
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
    51
    let run = subcommand_run_fn(subcommand_name)
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
    52
        .expect("unknown subcommand name from clap despite AppSettings::SubcommandRequired");
46631
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
    53
    let subcommand_args = subcommand_matches
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
    54
        .expect("no subcommand arguments from clap despite AppSettings::SubcommandRequired");
45051
18f8d3b31baa rhg: add a limited `rhg root` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45050
diff changeset
    55
46555
d8730ff51d5a rhg: Add support for -R and --repository command-line arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46554
diff changeset
    56
    // Global arguments can be in either based on e.g. `hg -R ./foo log` v.s.
d8730ff51d5a rhg: Add support for -R and --repository command-line arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46554
diff changeset
    57
    // `hg log -R ./foo`
46631
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
    58
    let value_of_global_arg = |name| {
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
    59
        subcommand_args
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
    60
            .value_of_os(name)
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
    61
            .or_else(|| matches.value_of_os(name))
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
    62
    };
46556
2e5dd18d6dc3 rhg: Add support for --config CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46555
diff changeset
    63
    // For arguments where multiple occurences are allowed, return a
2e5dd18d6dc3 rhg: Add support for --config CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46555
diff changeset
    64
    // possibly-iterator of all values.
2e5dd18d6dc3 rhg: Add support for --config CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46555
diff changeset
    65
    let values_of_global_arg = |name: &str| {
2e5dd18d6dc3 rhg: Add support for --config CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46555
diff changeset
    66
        let a = matches.values_of_os(name).into_iter().flatten();
46631
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
    67
        let b = subcommand_args.values_of_os(name).into_iter().flatten();
46556
2e5dd18d6dc3 rhg: Add support for --config CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46555
diff changeset
    68
        a.chain(b)
2e5dd18d6dc3 rhg: Add support for --config CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46555
diff changeset
    69
    };
46555
d8730ff51d5a rhg: Add support for -R and --repository command-line arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46554
diff changeset
    70
46630
21d3b40b4c0e rhg: Remove error message on unsupported CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46557
diff changeset
    71
    let config_args = values_of_global_arg("config")
21d3b40b4c0e rhg: Remove error message on unsupported CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46557
diff changeset
    72
        // `get_bytes_from_path` works for OsStr the same as for Path
21d3b40b4c0e rhg: Remove error message on unsupported CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46557
diff changeset
    73
        .map(hg::utils::files::get_bytes_from_path);
46631
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
    74
    let non_repo_config = &hg::config::Config::load(config_args)?;
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
    75
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
    76
    let repo_path = value_of_global_arg("repository").map(Path::new);
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
    77
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
    78
    run(&CliInvocation {
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
    79
        ui,
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
    80
        subcommand_args,
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
    81
        non_repo_config,
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
    82
        repo_path,
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
    83
    })
46630
21d3b40b4c0e rhg: Remove error message on unsupported CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46557
diff changeset
    84
}
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
    85
46630
21d3b40b4c0e rhg: Remove error message on unsupported CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46557
diff changeset
    86
fn main() {
46631
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
    87
    let ui = Ui::new();
46630
21d3b40b4c0e rhg: Remove error message on unsupported CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46557
diff changeset
    88
21d3b40b4c0e rhg: Remove error message on unsupported CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46557
diff changeset
    89
    let exit_code = match main_with_result(&ui) {
21d3b40b4c0e rhg: Remove error message on unsupported CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46557
diff changeset
    90
        Ok(()) => exitcode::OK,
46513
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 45938
diff changeset
    91
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 45938
diff changeset
    92
        // Exit with a specific code and no error message to let a potential
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 45938
diff changeset
    93
        // wrapper script fallback to Python-based Mercurial.
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 45938
diff changeset
    94
        Err(CommandError::Unimplemented) => exitcode::UNIMPLEMENTED,
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 45938
diff changeset
    95
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 45938
diff changeset
    96
        Err(CommandError::Abort { message }) => {
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 45938
diff changeset
    97
            if !message.is_empty() {
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 45938
diff changeset
    98
                // Ignore errors when writing to stderr, we’re already exiting
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 45938
diff changeset
    99
                // with failure code so there’s not much more we can do.
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 45938
diff changeset
   100
                let _ =
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 45938
diff changeset
   101
                    ui.write_stderr(&format_bytes!(b"abort: {}\n", message));
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 45938
diff changeset
   102
            }
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 45938
diff changeset
   103
            exitcode::ABORT
45381
47997afadf08 rhg: ask the error message from `CommandError`
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45051
diff changeset
   104
        }
46513
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 45938
diff changeset
   105
    };
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 45938
diff changeset
   106
    std::process::exit(exit_code)
45001
cf04f62d1579 rhg: add rhg crate
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff changeset
   107
}
45535
f17caf8f3fef rhg: add a limited `rhg debugdata` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45451
diff changeset
   108
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   109
macro_rules! subcommands {
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   110
    ($( $command: ident )+) => {
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   111
        mod commands {
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   112
            $(
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   113
                pub mod $command;
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   114
            )+
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   115
        }
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   116
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   117
        fn add_subcommand_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   118
            app
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   119
            $(
46555
d8730ff51d5a rhg: Add support for -R and --repository command-line arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46554
diff changeset
   120
                .subcommand(add_global_args(commands::$command::args()))
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   121
            )+
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   122
        }
46543
a6e4e4650bac rhg: Parse system and user configuration at program start
Simon Sapin <simon.sapin@octobus.net>
parents: 46513
diff changeset
   123
46631
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
   124
        pub type RunFn = fn(&CliInvocation) -> Result<(), CommandError>;
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
   125
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
   126
        fn subcommand_run_fn(name: &str) -> Option<RunFn> {
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   127
            match name {
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   128
                $(
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   129
                    stringify!($command) => Some(commands::$command::run),
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   130
                )+
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   131
                _ => None,
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   132
            }
45548
33ded2d3f4fc rhg: add a limited `rhg cat -r` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45543
diff changeset
   133
        }
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   134
    };
45535
f17caf8f3fef rhg: add a limited `rhg debugdata` subcommand
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45451
diff changeset
   135
}
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   136
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   137
subcommands! {
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   138
    cat
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   139
    debugdata
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   140
    debugrequirements
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   141
    files
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   142
    root
46557
a25033eb43b5 rhg: add limited support for the `config` sub-command
Simon Sapin <simon.sapin@octobus.net>
parents: 46556
diff changeset
   143
    config
46554
95d37db31479 rhg: Replace subcommand boilerplate with a macro
Simon Sapin <simon.sapin@octobus.net>
parents: 46553
diff changeset
   144
}
46631
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
   145
pub struct CliInvocation<'a> {
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
   146
    ui: &'a Ui,
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
   147
    subcommand_args: &'a ArgMatches<'a>,
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
   148
    non_repo_config: &'a Config,
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
   149
    repo_path: Option<&'a Path>,
80840b651721 rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents: 46630
diff changeset
   150
}