view rust/rhg/src/commands/debugrequirements.rs @ 49375:044e42ae45d9 stable

rhg: add error message for paths outside the repository when cwd != root This mirrors the Python implementation. The relative path handling should probably be refactored into a util, but it it out of scope for this change.
author Rapha?l Gom?s <rgomes@octobus.net>
date Wed, 25 May 2022 16:50:00 +0200
parents 5ce2aa7c2ad5
children 37bc3edef76f
line wrap: on
line source

use crate::error::CommandError;

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(invocation: &crate::CliInvocation) -> Result<(), CommandError> {
    let repo = invocation.repo?;
    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');
    }
    invocation.ui.write_stdout(output.as_bytes())?;
    Ok(())
}