equal
deleted
inserted
replaced
|
1 use crate::commands::Command; |
|
2 use crate::error::{CommandError, CommandErrorKind}; |
|
3 use crate::ui::Ui; |
|
4 use hg::operations::{ListTrackedFiles, ListTrackedFilesErrorKind}; |
|
5 |
|
6 pub const HELP_TEXT: &str = " |
|
7 List tracked files. |
|
8 |
|
9 Returns 0 on success. |
|
10 "; |
|
11 |
|
12 pub struct FilesCommand<'a> { |
|
13 ui: &'a Ui, |
|
14 } |
|
15 |
|
16 impl<'a> FilesCommand<'a> { |
|
17 pub fn new(ui: &'a Ui) -> Self { |
|
18 FilesCommand { ui } |
|
19 } |
|
20 } |
|
21 |
|
22 impl<'a> Command<'a> for FilesCommand<'a> { |
|
23 fn run(&self) -> Result<(), CommandError> { |
|
24 let operation_builder = ListTrackedFiles::new()?; |
|
25 let operation = operation_builder.load().map_err(|err| { |
|
26 CommandErrorKind::Abort(Some( |
|
27 [b"abort: ", err.to_string().as_bytes(), b"\n"] |
|
28 .concat() |
|
29 .to_vec(), |
|
30 )) |
|
31 })?; |
|
32 let files = operation.run().map_err(|err| match err.kind { |
|
33 ListTrackedFilesErrorKind::ParseError(_) => { |
|
34 CommandErrorKind::Abort(Some( |
|
35 // TODO find a better error message |
|
36 b"abort: parse error\n".to_vec(), |
|
37 )) |
|
38 } |
|
39 })?; |
|
40 |
|
41 let mut stdout = self.ui.stdout_buffer(); |
|
42 for file in files { |
|
43 stdout.write_all(file.as_bytes())?; |
|
44 stdout.write_all(b"\n")?; |
|
45 } |
|
46 stdout.flush()?; |
|
47 |
|
48 Ok(()) |
|
49 } |
|
50 } |