root.rs
34 lines
| 731 B
| application/rls-services+xml
|
RustLexer
Antoine Cezar
|
r45592 | use crate::commands::Command; | ||
Antoine Cezar
|
r45922 | use crate::error::CommandError; | ||
Antoine Cezar
|
r45592 | use crate::ui::Ui; | ||
Antoine Cezar
|
r45922 | use hg::operations::FindRoot; | ||
Antoine Cezar
|
r45592 | use hg::utils::files::get_bytes_from_path; | ||
pub const HELP_TEXT: &str = " | ||||
Print the root directory of the current repository. | ||||
Returns 0 on success. | ||||
"; | ||||
Antoine Cezar
|
r45920 | pub struct RootCommand<'a> { | ||
ui: &'a Ui, | ||||
} | ||||
impl<'a> RootCommand<'a> { | ||||
pub fn new(ui: &'a Ui) -> Self { | ||||
RootCommand { ui } | ||||
} | ||||
Antoine Cezar
|
r45592 | } | ||
Antoine Cezar
|
r45920 | impl<'a> Command<'a> for RootCommand<'a> { | ||
fn run(&self) -> Result<(), CommandError> { | ||||
Antoine Cezar
|
r45922 | let path_buf = FindRoot::new().run()?; | ||
Antoine Cezar
|
r45592 | |||
let bytes = get_bytes_from_path(path_buf); | ||||
// TODO use formating macro | ||||
self.ui.write_stdout(&[bytes.as_slice(), b"\n"].concat())?; | ||||
Antoine Cezar
|
r45919 | Ok(()) | ||
Antoine Cezar
|
r45592 | } | ||
} | ||||