rust/rhg/src/commands/debugrequirements.rs
author Simon Sapin <simon.sapin@octobus.net>
Mon, 14 Dec 2020 16:33:15 +0100
changeset 46167 8a4914397d02
parent 46135 dca9cb99971c
child 46462 d03b0601e0eb
permissions -rw-r--r--
rust: introduce Repo and Vfs types for filesystem abstraction This is similar to the corresponding Python classes. Repo represents a repository and knows the path to the `.hg` directory, the `store` directory, and the working directory. Separating these will enable supporting the share extension. A Vfs is created from a Repo for one of these three directories. It has filesystem access APIs that take a relative std::path::Path as a parameter. Differential Revision: https://phab.mercurial-scm.org/D9596

use crate::commands::Command;
use crate::error::CommandError;
use crate::ui::Ui;
use hg::repo::Repo;
use hg::requirements;

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

pub struct DebugRequirementsCommand {}

impl DebugRequirementsCommand {
    pub fn new() -> Self {
        DebugRequirementsCommand {}
    }
}

impl Command for DebugRequirementsCommand {
    fn run(&self, ui: &Ui) -> Result<(), CommandError> {
        let repo = Repo::find()?;
        let mut output = String::new();
        for req in requirements::load(&repo)? {
            output.push_str(&req);
            output.push('\n');
        }
        ui.write_stdout(output.as_bytes())?;
        Ok(())
    }
}