Mercurial > public > mercurial-scm > hg-stable
comparison rust/rhg/src/commands/files.rs @ 45449:ed95ccc94333
rhg: pass `ui` to `Command` `run`
Allow implementation of `From<clap::ArgMatches> for Command`
Differential Revision: https://phab.mercurial-scm.org/D8954
author | Antoine Cezar <antoine.cezar@octobus.net> |
---|---|
date | Tue, 04 Aug 2020 16:11:23 +0200 |
parents | 1b3197047f5c |
children | 72b7d58d6e35 |
comparison
equal
deleted
inserted
replaced
45448:e339693addc0 | 45449:ed95ccc94333 |
---|---|
9 List tracked files. | 9 List tracked files. |
10 | 10 |
11 Returns 0 on success. | 11 Returns 0 on success. |
12 "; | 12 "; |
13 | 13 |
14 pub struct FilesCommand<'a> { | 14 pub struct FilesCommand {} |
15 ui: &'a Ui, | |
16 } | |
17 | 15 |
18 impl<'a> FilesCommand<'a> { | 16 impl FilesCommand { |
19 pub fn new(ui: &'a Ui) -> Self { | 17 pub fn new() -> Self { |
20 FilesCommand { ui } | 18 FilesCommand {} |
21 } | 19 } |
22 } | 20 } |
23 | 21 |
24 impl<'a> Command<'a> for FilesCommand<'a> { | 22 impl Command for FilesCommand { |
25 fn run(&self) -> Result<(), CommandError> { | 23 fn run(&self, ui: &Ui) -> Result<(), CommandError> { |
26 let operation_builder = ListTrackedFiles::new()?; | 24 let operation_builder = ListTrackedFiles::new()?; |
27 let operation = operation_builder.load().map_err(|err| { | 25 let operation = operation_builder.load().map_err(|err| { |
28 CommandErrorKind::Abort(Some( | 26 CommandErrorKind::Abort(Some( |
29 [b"abort: ", err.to_string().as_bytes(), b"\n"] | 27 [b"abort: ", err.to_string().as_bytes(), b"\n"] |
30 .concat() | 28 .concat() |
45 let rooted_cwd = cwd | 43 let rooted_cwd = cwd |
46 .strip_prefix(operation_builder.get_root()) | 44 .strip_prefix(operation_builder.get_root()) |
47 .expect("cwd was already checked within the repository"); | 45 .expect("cwd was already checked within the repository"); |
48 let rooted_cwd = HgPathBuf::from(get_bytes_from_path(rooted_cwd)); | 46 let rooted_cwd = HgPathBuf::from(get_bytes_from_path(rooted_cwd)); |
49 | 47 |
50 let mut stdout = self.ui.stdout_buffer(); | 48 let mut stdout = ui.stdout_buffer(); |
51 | 49 |
52 for file in files { | 50 for file in files { |
53 stdout.write_all(relativize_path(file, &rooted_cwd).as_ref())?; | 51 stdout.write_all(relativize_path(file, &rooted_cwd).as_ref())?; |
54 stdout.write_all(b"\n")?; | 52 stdout.write_all(b"\n")?; |
55 } | 53 } |