root.rs
28 lines
| 889 B
| application/rls-services+xml
|
RustLexer
Antoine Cezar
|
r45922 | use crate::error::CommandError; | ||
Raphaël Gomès
|
r46598 | use format_bytes::format_bytes; | ||
Simon Sapin
|
r47474 | use hg::errors::{IoErrorContext, IoResultExt}; | ||
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. | ||||
"; | ||||
Simon Sapin
|
r47251 | pub fn args() -> clap::App<'static, 'static> { | ||
clap::SubCommand::with_name("root").about(HELP_TEXT) | ||||
} | ||||
Simon Sapin
|
r47334 | pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> { | ||
Simon Sapin
|
r47335 | let repo = invocation.repo?; | ||
Simon Sapin
|
r47474 | let working_directory = repo.working_directory_path(); | ||
let working_directory = std::fs::canonicalize(working_directory) | ||||
.with_context(|| { | ||||
IoErrorContext::CanonicalizingPath(working_directory.to_owned()) | ||||
})?; | ||||
let bytes = get_bytes_from_path(&working_directory); | ||||
Simon Sapin
|
r47334 | invocation | ||
.ui | ||||
.write_stdout(&format_bytes!(b"{}\n", bytes.as_slice()))?; | ||||
Simon Sapin
|
r47250 | Ok(()) | ||
Antoine Cezar
|
r45592 | } | ||