Mercurial > public > mercurial-scm > hg
comparison rust/rhg/src/commands/root.rs @ 46500:184e46550dc8
rhg: replace command structs with functions
The `Command` trait was not used in any generic context,
and the struct where nothing more than holders for values parsed from CLI
arguments to be available to a `run` method.
Differential Revision: https://phab.mercurial-scm.org/D9967
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Mon, 08 Feb 2021 20:33:04 +0100 |
parents | a6e4e4650bac |
children | 1ecaf09d9964 |
comparison
equal
deleted
inserted
replaced
46499:eace48b4a786 | 46500:184e46550dc8 |
---|---|
1 use crate::commands::Command; | |
2 use crate::error::CommandError; | 1 use crate::error::CommandError; |
3 use crate::ui::Ui; | 2 use crate::ui::Ui; |
3 use clap::ArgMatches; | |
4 use format_bytes::format_bytes; | 4 use format_bytes::format_bytes; |
5 use hg::config::Config; | 5 use hg::config::Config; |
6 use hg::repo::Repo; | 6 use hg::repo::Repo; |
7 use hg::utils::files::get_bytes_from_path; | 7 use hg::utils::files::get_bytes_from_path; |
8 | 8 |
10 Print the root directory of the current repository. | 10 Print the root directory of the current repository. |
11 | 11 |
12 Returns 0 on success. | 12 Returns 0 on success. |
13 "; | 13 "; |
14 | 14 |
15 pub struct RootCommand {} | 15 pub fn run( |
16 | 16 ui: &Ui, |
17 impl RootCommand { | 17 config: &Config, |
18 pub fn new() -> Self { | 18 _args: &ArgMatches, |
19 RootCommand {} | 19 ) -> Result<(), CommandError> { |
20 } | 20 let repo = Repo::find(config)?; |
21 let bytes = get_bytes_from_path(repo.working_directory_path()); | |
22 ui.write_stdout(&format_bytes!(b"{}\n", bytes.as_slice()))?; | |
23 Ok(()) | |
21 } | 24 } |
22 | |
23 impl Command for RootCommand { | |
24 fn run(&self, ui: &Ui, config: &Config) -> Result<(), CommandError> { | |
25 let repo = Repo::find(config)?; | |
26 let bytes = get_bytes_from_path(repo.working_directory_path()); | |
27 ui.write_stdout(&format_bytes!(b"{}\n", bytes.as_slice()))?; | |
28 Ok(()) | |
29 } | |
30 } |