view rust/rhg/src/commands/root.rs @ 46501:1ecaf09d9964

rhg: Move subcommand CLI arguments definitions to respective modules Differential Revision: https://phab.mercurial-scm.org/D9968
author Simon Sapin <simon.sapin@octobus.net>
date Mon, 08 Feb 2021 21:05:36 +0100
parents 184e46550dc8
children d8730ff51d5a
line wrap: on
line source

use crate::error::CommandError;
use crate::ui::Ui;
use clap::ArgMatches;
use format_bytes::format_bytes;
use hg::config::Config;
use hg::repo::Repo;
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.
";

pub fn args() -> clap::App<'static, 'static> {
    clap::SubCommand::with_name("root").about(HELP_TEXT)
}

pub fn run(
    ui: &Ui,
    config: &Config,
    _args: &ArgMatches,
) -> Result<(), CommandError> {
    let repo = Repo::find(config)?;
    let bytes = get_bytes_from_path(repo.working_directory_path());
    ui.write_stdout(&format_bytes!(b"{}\n", bytes.as_slice()))?;
    Ok(())
}