##// END OF EJS Templates
rhg: add a `Files` `Command` to prepare the `rhg files` subcommand...
Antoine Cezar -
r45923:5fe25f8e default
parent child Browse files
Show More
@@ -0,0 +1,50 b''
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 }
@@ -57,6 +57,7 b' pub type FastHashMap<K, V> = HashMap<K, '
57 pub enum DirstateParseError {
57 pub enum DirstateParseError {
58 TooLittleData,
58 TooLittleData,
59 Overflow,
59 Overflow,
60 // TODO refactor to use bytes instead of String
60 CorruptedEntry(String),
61 CorruptedEntry(String),
61 Damaged,
62 Damaged,
62 }
63 }
@@ -1,3 +1,4 b''
1 pub mod files;
1 pub mod root;
2 pub mod root;
2 use crate::error::CommandError;
3 use crate::error::CommandError;
3
4
@@ -16,6 +16,8 b' pub enum CommandErrorKind {'
16 StdoutError,
16 StdoutError,
17 /// The standard error stream cannot be written to
17 /// The standard error stream cannot be written to
18 StderrError,
18 StderrError,
19 /// The command aborted
20 Abort(Option<Vec<u8>>),
19 }
21 }
20
22
21 impl CommandErrorKind {
23 impl CommandErrorKind {
@@ -25,6 +27,7 b' impl CommandErrorKind {'
25 CommandErrorKind::CurrentDirNotFound(_) => exitcode::ABORT,
27 CommandErrorKind::CurrentDirNotFound(_) => exitcode::ABORT,
26 CommandErrorKind::StdoutError => exitcode::ABORT,
28 CommandErrorKind::StdoutError => exitcode::ABORT,
27 CommandErrorKind::StderrError => exitcode::ABORT,
29 CommandErrorKind::StderrError => exitcode::ABORT,
30 CommandErrorKind::Abort(_) => exitcode::ABORT,
28 }
31 }
29 }
32 }
30
33
@@ -52,6 +55,7 b' impl CommandErrorKind {'
52 ]
55 ]
53 .concat(),
56 .concat(),
54 ),
57 ),
58 CommandErrorKind::Abort(message) => message.to_owned(),
55 _ => None,
59 _ => None,
56 }
60 }
57 }
61 }
General Comments 0
You need to be logged in to leave comments. Login now