##// END OF EJS Templates
rhg: simplify `FindRootError` handling...
Antoine Cezar -
r45922:5dbf875b default
parent child Browse files
Show More
@@ -1,7 +1,7 b''
1 1 use crate::commands::Command;
2 use crate::error::{CommandError, CommandErrorKind};
2 use crate::error::CommandError;
3 3 use crate::ui::Ui;
4 use hg::operations::{FindRoot, FindRootErrorKind};
4 use hg::operations::FindRoot;
5 5 use hg::utils::files::get_bytes_from_path;
6 6
7 7 pub const HELP_TEXT: &str = "
@@ -22,15 +22,7 b" impl<'a> RootCommand<'a> {"
22 22
23 23 impl<'a> Command<'a> for RootCommand<'a> {
24 24 fn run(&self) -> Result<(), CommandError> {
25 let path_buf =
26 FindRoot::new().run().map_err(|err| match err.kind {
27 FindRootErrorKind::RootNotFound(path) => {
28 CommandErrorKind::RootNotFound(path)
29 }
30 FindRootErrorKind::GetCurrentDirError(e) => {
31 CommandErrorKind::CurrentDirNotFound(e)
32 }
33 })?;
25 let path_buf = FindRoot::new().run()?;
34 26
35 27 let bytes = get_bytes_from_path(path_buf);
36 28
@@ -1,5 +1,6 b''
1 1 use crate::exitcode;
2 2 use crate::ui::UiError;
3 use hg::operations::{FindRootError, FindRootErrorKind};
3 4 use hg::utils::files::get_bytes_from_path;
4 5 use std::convert::From;
5 6 use std::path::PathBuf;
@@ -90,3 +91,16 b' impl From<UiError> for CommandError {'
90 91 }
91 92 }
92 93 }
94
95 impl From<FindRootError> for CommandError {
96 fn from(err: FindRootError) -> Self {
97 match err.kind {
98 FindRootErrorKind::RootNotFound(path) => CommandError {
99 kind: CommandErrorKind::RootNotFound(path),
100 },
101 FindRootErrorKind::GetCurrentDirError(e) => CommandError {
102 kind: CommandErrorKind::CurrentDirNotFound(e),
103 },
104 }
105 }
106 }
General Comments 0
You need to be logged in to leave comments. Login now