Show More
@@ -1,10 +1,11 b'' | |||
|
1 | 1 | pub mod files; |
|
2 | 2 | pub mod root; |
|
3 | 3 | use crate::error::CommandError; |
|
4 | use crate::ui::Ui; | |
|
4 | 5 | |
|
5 | 6 | /// The common trait for rhg commands |
|
6 | 7 | /// |
|
7 | 8 | /// Normalize the interface of the commands provided by rhg |
|
8 |
pub trait Command |
|
|
9 | fn run(&self) -> Result<(), CommandError>; | |
|
9 | pub trait Command { | |
|
10 | fn run(&self, ui: &Ui) -> Result<(), CommandError>; | |
|
10 | 11 | } |
@@ -11,18 +11,16 b' List tracked files.' | |||
|
11 | 11 | Returns 0 on success. |
|
12 | 12 | "; |
|
13 | 13 | |
|
14 |
pub struct FilesCommand |
|
|
15 | ui: &'a Ui, | |
|
16 | } | |
|
14 | pub struct FilesCommand {} | |
|
17 | 15 | |
|
18 |
impl |
|
|
19 |
pub fn new( |
|
|
20 |
FilesCommand { |
|
|
16 | impl FilesCommand { | |
|
17 | pub fn new() -> Self { | |
|
18 | FilesCommand {} | |
|
21 | 19 | } |
|
22 | 20 | } |
|
23 | 21 | |
|
24 |
impl |
|
|
25 | fn run(&self) -> Result<(), CommandError> { | |
|
22 | impl Command for FilesCommand { | |
|
23 | fn run(&self, ui: &Ui) -> Result<(), CommandError> { | |
|
26 | 24 | let operation_builder = ListTrackedFiles::new()?; |
|
27 | 25 | let operation = operation_builder.load().map_err(|err| { |
|
28 | 26 | CommandErrorKind::Abort(Some( |
@@ -47,7 +45,7 b" impl<'a> Command<'a> for FilesCommand<'a" | |||
|
47 | 45 | .expect("cwd was already checked within the repository"); |
|
48 | 46 | let rooted_cwd = HgPathBuf::from(get_bytes_from_path(rooted_cwd)); |
|
49 | 47 | |
|
50 |
let mut stdout = |
|
|
48 | let mut stdout = ui.stdout_buffer(); | |
|
51 | 49 | |
|
52 | 50 | for file in files { |
|
53 | 51 | stdout.write_all(relativize_path(file, &rooted_cwd).as_ref())?; |
@@ -10,24 +10,22 b' Print the root directory of the current ' | |||
|
10 | 10 | Returns 0 on success. |
|
11 | 11 | "; |
|
12 | 12 | |
|
13 |
pub struct RootCommand |
|
|
14 | ui: &'a Ui, | |
|
15 | } | |
|
13 | pub struct RootCommand {} | |
|
16 | 14 | |
|
17 |
impl |
|
|
18 |
pub fn new( |
|
|
19 |
RootCommand { |
|
|
15 | impl RootCommand { | |
|
16 | pub fn new() -> Self { | |
|
17 | RootCommand {} | |
|
20 | 18 | } |
|
21 | 19 | } |
|
22 | 20 | |
|
23 |
impl |
|
|
24 | fn run(&self) -> Result<(), CommandError> { | |
|
21 | impl Command for RootCommand { | |
|
22 | fn run(&self, ui: &Ui) -> Result<(), CommandError> { | |
|
25 | 23 | let path_buf = FindRoot::new().run()?; |
|
26 | 24 | |
|
27 | 25 | let bytes = get_bytes_from_path(path_buf); |
|
28 | 26 | |
|
29 | 27 | // TODO use formating macro |
|
30 |
|
|
|
28 | ui.write_stdout(&[bytes.as_slice(), b"\n"].concat())?; | |
|
31 | 29 | |
|
32 | 30 | Ok(()) |
|
33 | 31 | } |
@@ -29,8 +29,8 b' fn main() {' | |||
|
29 | 29 | |
|
30 | 30 | let command_result = match matches.subcommand_name() { |
|
31 | 31 | Some(name) => match name { |
|
32 |
"root" => commands::root::RootCommand::new( |
|
|
33 |
"files" => commands::files::FilesCommand::new( |
|
|
32 | "root" => commands::root::RootCommand::new().run(&ui), | |
|
33 | "files" => commands::files::FilesCommand::new().run(&ui), | |
|
34 | 34 | _ => std::process::exit(exitcode::UNIMPLEMENTED_COMMAND), |
|
35 | 35 | }, |
|
36 | 36 | _ => { |
General Comments 0
You need to be logged in to leave comments.
Login now