45 let args = subcommand_matches |
56 let args = subcommand_matches |
46 .expect("no subcommand arguments from clap despite AppSettings::SubcommandRequired"); |
57 .expect("no subcommand arguments from clap despite AppSettings::SubcommandRequired"); |
47 |
58 |
48 // Global arguments can be in either based on e.g. `hg -R ./foo log` v.s. |
59 // Global arguments can be in either based on e.g. `hg -R ./foo log` v.s. |
49 // `hg log -R ./foo` |
60 // `hg log -R ./foo` |
50 let global_arg = |
61 let value_of_global_arg = |
51 |name| args.value_of_os(name).or_else(|| matches.value_of_os(name)); |
62 |name| args.value_of_os(name).or_else(|| matches.value_of_os(name)); |
|
63 // For arguments where multiple occurences are allowed, return a |
|
64 // possibly-iterator of all values. |
|
65 let values_of_global_arg = |name: &str| { |
|
66 let a = matches.values_of_os(name).into_iter().flatten(); |
|
67 let b = args.values_of_os(name).into_iter().flatten(); |
|
68 a.chain(b) |
|
69 }; |
52 |
70 |
53 let repo_path = global_arg("repository").map(Path::new); |
71 let repo_path = value_of_global_arg("repository").map(Path::new); |
54 let result = (|| -> Result<(), CommandError> { |
72 let result = (|| -> Result<(), CommandError> { |
55 let config = hg::config::Config::load()?; |
73 let config_args = values_of_global_arg("config") |
|
74 // `get_bytes_from_path` works for OsStr the same as for Path |
|
75 .map(hg::utils::files::get_bytes_from_path); |
|
76 let config = hg::config::Config::load(config_args)?; |
56 run(&ui, &config, repo_path, args) |
77 run(&ui, &config, repo_path, args) |
57 })(); |
78 })(); |
58 |
79 |
59 let exit_code = match result { |
80 let exit_code = match result { |
60 Ok(_) => exitcode::OK, |
81 Ok(_) => exitcode::OK, |