config.rs
37 lines
| 1.0 KiB
| application/rls-services+xml
|
RustLexer
|
r47255 | 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. | ||||
"; | ||||
|
r50534 | pub fn args() -> clap::Command { | ||
clap::command!("config") | ||||
|
r47255 | .arg( | ||
|
r50534 | Arg::new("name") | ||
|
r47255 | .help("the section.name to print") | ||
.value_name("NAME") | ||||
|
r50534 | .required(true), | ||
|
r47255 | ) | ||
.about(HELP_TEXT) | ||||
} | ||||
|
r47334 | pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> { | ||
let (section, name) = invocation | ||||
.subcommand_args | ||||
|
r50534 | .get_one::<String>("name") | ||
|
r47255 | .expect("missing required CLI argument") | ||
.as_bytes() | ||||
.split_2(b'.') | ||||
|
r47460 | .ok_or_else(|| HgError::unsupported("hg config <section>"))?; | ||
|
r47255 | |||
|
r47481 | if let Some(value) = invocation.config.get(section, name) { | ||
invocation.ui.write_stdout(&format_bytes!(b"{}\n", value))?; | ||||
Ok(()) | ||||
} else { | ||||
Err(CommandError::Unsuccessful) | ||||
} | ||||
|
r47255 | } | ||