author | Simon Sapin <simon.sapin@octobus.net> |
Mon, 15 Feb 2021 20:13:09 +0100 | |
changeset 46632 | 5ce2aa7c2ad5 |
parent 46631 | 80840b651721 |
child 46753 | 97ac588b6d9e |
permissions | -rw-r--r-- |
45383
5dbf875b3275
rhg: simplify `FindRootError` handling
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45381
diff
changeset
|
1 |
use crate::error::CommandError; |
45999
fada33872b5b
rhg: use `format_bytes!` for error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
45449
diff
changeset
|
2 |
use format_bytes::format_bytes; |
45050
513b3ef277a3
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
3 |
use hg::utils::files::get_bytes_from_path; |
513b3ef277a3
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
4 |
|
513b3ef277a3
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
5 |
pub const HELP_TEXT: &str = " |
513b3ef277a3
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
6 |
Print the root directory of the current repository. |
513b3ef277a3
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
7 |
|
513b3ef277a3
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
8 |
Returns 0 on success. |
513b3ef277a3
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
9 |
"; |
513b3ef277a3
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
10 |
|
46553
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
11 |
pub fn args() -> clap::App<'static, 'static> { |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
12 |
clap::SubCommand::with_name("root").about(HELP_TEXT) |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
13 |
} |
1ecaf09d9964
rhg: Move subcommand CLI arguments definitions to respective modules
Simon Sapin <simon.sapin@octobus.net>
parents:
46552
diff
changeset
|
14 |
|
46631
80840b651721
rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents:
46555
diff
changeset
|
15 |
pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> { |
46632
5ce2aa7c2ad5
rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents:
46631
diff
changeset
|
16 |
let repo = invocation.repo?; |
46552
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46543
diff
changeset
|
17 |
let bytes = get_bytes_from_path(repo.working_directory_path()); |
46631
80840b651721
rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents:
46555
diff
changeset
|
18 |
invocation |
80840b651721
rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents:
46555
diff
changeset
|
19 |
.ui |
80840b651721
rhg: Group values passed to every sub-command into a struct
Simon Sapin <simon.sapin@octobus.net>
parents:
46555
diff
changeset
|
20 |
.write_stdout(&format_bytes!(b"{}\n", bytes.as_slice()))?; |
46552
184e46550dc8
rhg: replace command structs with functions
Simon Sapin <simon.sapin@octobus.net>
parents:
46543
diff
changeset
|
21 |
Ok(()) |
45050
513b3ef277a3
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
diff
changeset
|
22 |
} |