rust/rhg/src/commands/debugrequirements.rs
author Simon Sapin <simon.sapin@octobus.net>
Mon, 08 Feb 2021 21:37:30 +0100
changeset 46503 d8730ff51d5a
parent 46501 1ecaf09d9964
child 46592 80840b651721
permissions -rw-r--r--
rhg: Add support for -R and --repository command-line arguments Differential Revision: https://phab.mercurial-scm.org/D9970

use crate::error::CommandError;
use crate::ui::Ui;
use clap::ArgMatches;
use hg::config::Config;
use hg::repo::Repo;
use std::path::Path;

pub const HELP_TEXT: &str = "
Print the current repo requirements.
";

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

pub fn run(
    ui: &Ui,
    config: &Config,
    repo_path: Option<&Path>,
    _args: &ArgMatches,
) -> Result<(), CommandError> {
    let repo = Repo::find(config, repo_path)?;
    let mut output = String::new();
    let mut requirements: Vec<_> = repo.requirements().iter().collect();
    requirements.sort();
    for req in requirements {
        output.push_str(req);
        output.push('\n');
    }
    ui.write_stdout(output.as_bytes())?;
    Ok(())
}