Mercurial > public > mercurial-scm > hg
annotate rust/rhg/src/commands/debugrequirements.rs @ 46484:a6e4e4650bac
rhg: Parse system and user configuration at program start
? and pass it around up to `Repo::find`
Differential Revision: https://phab.mercurial-scm.org/D9962
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Thu, 04 Feb 2021 13:17:55 +0100 |
parents | d03b0601e0eb |
children | 184e46550dc8 |
rev | line source |
---|---|
45923
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
1 use crate::commands::Command; |
45924
a2eda1ff22aa
requirements: move loading to hg-core and add parsing
Simon Sapin <simon-commits@exyr.org>
parents:
45923
diff
changeset
|
2 use crate::error::CommandError; |
45923
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
3 use crate::ui::Ui; |
46484
a6e4e4650bac
rhg: Parse system and user configuration at program start
Simon Sapin <simon.sapin@octobus.net>
parents:
46462
diff
changeset
|
4 use hg::config::Config; |
46167
8a4914397d02
rust: introduce Repo and Vfs types for filesystem abstraction
Simon Sapin <simon.sapin@octobus.net>
parents:
46135
diff
changeset
|
5 use hg::repo::Repo; |
45923
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
6 |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
7 pub const HELP_TEXT: &str = " |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
8 Print the current repo requirements. |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
9 "; |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
10 |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
11 pub struct DebugRequirementsCommand {} |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
12 |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
13 impl DebugRequirementsCommand { |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
14 pub fn new() -> Self { |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
15 DebugRequirementsCommand {} |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
16 } |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
17 } |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
18 |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
19 impl Command for DebugRequirementsCommand { |
46484
a6e4e4650bac
rhg: Parse system and user configuration at program start
Simon Sapin <simon.sapin@octobus.net>
parents:
46462
diff
changeset
|
20 fn run(&self, ui: &Ui, config: &Config) -> Result<(), CommandError> { |
a6e4e4650bac
rhg: Parse system and user configuration at program start
Simon Sapin <simon.sapin@octobus.net>
parents:
46462
diff
changeset
|
21 let repo = Repo::find(config)?; |
45924
a2eda1ff22aa
requirements: move loading to hg-core and add parsing
Simon Sapin <simon-commits@exyr.org>
parents:
45923
diff
changeset
|
22 let mut output = String::new(); |
46462
d03b0601e0eb
rhg: initial support for shared repositories
Simon Sapin <simon.sapin@octobus.net>
parents:
46167
diff
changeset
|
23 let mut requirements: Vec<_> = repo.requirements().iter().collect(); |
d03b0601e0eb
rhg: initial support for shared repositories
Simon Sapin <simon.sapin@octobus.net>
parents:
46167
diff
changeset
|
24 requirements.sort(); |
d03b0601e0eb
rhg: initial support for shared repositories
Simon Sapin <simon.sapin@octobus.net>
parents:
46167
diff
changeset
|
25 for req in requirements { |
d03b0601e0eb
rhg: initial support for shared repositories
Simon Sapin <simon.sapin@octobus.net>
parents:
46167
diff
changeset
|
26 output.push_str(req); |
45924
a2eda1ff22aa
requirements: move loading to hg-core and add parsing
Simon Sapin <simon-commits@exyr.org>
parents:
45923
diff
changeset
|
27 output.push('\n'); |
a2eda1ff22aa
requirements: move loading to hg-core and add parsing
Simon Sapin <simon-commits@exyr.org>
parents:
45923
diff
changeset
|
28 } |
a2eda1ff22aa
requirements: move loading to hg-core and add parsing
Simon Sapin <simon-commits@exyr.org>
parents:
45923
diff
changeset
|
29 ui.write_stdout(output.as_bytes())?; |
45923
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
30 Ok(()) |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
31 } |
ead435aa5294
rhg: add a `debugrequirements` subcommand
Simon Sapin <simon-commits@exyr.org>
parents:
diff
changeset
|
32 } |