view rust/rhg/src/commands/config.rs @ 49894:678588b01af1

rhg: implement checkexec to support weird filesystems In particular, some of our repos are stored on a fileserver that simulates POSIX permissions poorly, in such a way that prevents the removal of execute permission. This causes rhg show a spurious unclean status, even though python hg reports the repo as clean. We fix this by making rhg implement the ~same checkexec logic that python hg does.
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Thu, 05 Jan 2023 17:15:03 +0000
parents 37bc3edef76f
children
line wrap: on
line source

use crate::error::CommandError;
use clap::Arg;
use format_bytes::format_bytes;
use hg::errors::HgError;
use hg::utils::SliceExt;

pub const HELP_TEXT: &str = "
With one argument of the form section.name, print just the value of that config item.
";

pub fn args() -> clap::Command {
    clap::command!("config")
        .arg(
            Arg::new("name")
                .help("the section.name to print")
                .value_name("NAME")
                .required(true),
        )
        .about(HELP_TEXT)
}

pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> {
    let (section, name) = invocation
        .subcommand_args
        .get_one::<String>("name")
        .expect("missing required CLI argument")
        .as_bytes()
        .split_2(b'.')
        .ok_or_else(|| HgError::unsupported("hg config <section>"))?;

    if let Some(value) = invocation.config.get(section, name) {
        invocation.ui.write_stdout(&format_bytes!(b"{}\n", value))?;
        Ok(())
    } else {
        Err(CommandError::Unsuccessful)
    }
}