##// END OF EJS Templates
rhg: simplify `FindRootError` handling...
Antoine Cezar -
r45922:5dbf875b default
parent child Browse files
Show More
@@ -1,7 +1,7
1 use crate::commands::Command;
1 use crate::commands::Command;
2 use crate::error::{CommandError, CommandErrorKind};
2 use crate::error::CommandError;
3 use crate::ui::Ui;
3 use crate::ui::Ui;
4 use hg::operations::{FindRoot, FindRootErrorKind};
4 use hg::operations::FindRoot;
5 use hg::utils::files::get_bytes_from_path;
5 use hg::utils::files::get_bytes_from_path;
6
6
7 pub const HELP_TEXT: &str = "
7 pub const HELP_TEXT: &str = "
@@ -22,15 +22,7 impl<'a> RootCommand<'a> {
22
22
23 impl<'a> Command<'a> for RootCommand<'a> {
23 impl<'a> Command<'a> for RootCommand<'a> {
24 fn run(&self) -> Result<(), CommandError> {
24 fn run(&self) -> Result<(), CommandError> {
25 let path_buf =
25 let path_buf = FindRoot::new().run()?;
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 })?;
34
26
35 let bytes = get_bytes_from_path(path_buf);
27 let bytes = get_bytes_from_path(path_buf);
36
28
@@ -1,5 +1,6
1 use crate::exitcode;
1 use crate::exitcode;
2 use crate::ui::UiError;
2 use crate::ui::UiError;
3 use hg::operations::{FindRootError, FindRootErrorKind};
3 use hg::utils::files::get_bytes_from_path;
4 use hg::utils::files::get_bytes_from_path;
4 use std::convert::From;
5 use std::convert::From;
5 use std::path::PathBuf;
6 use std::path::PathBuf;
@@ -90,3 +91,16 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