| 1 |
use clap::Arg; |
| 2 |
use format_bytes::format_bytes; |
| 3 |
use hg::errors::HgError; |
| 4 |
use hg::utils::strings::SliceExt; |
| 5 |
|
| 6 |
use crate::error::CommandError; |
| 7 |
|
| 8 |
pub const HELP_TEXT: &str = " |
| 9 |
With one argument of the form section.name, print just the value of that config item. |
| 10 |
"; |
| 11 |
|
| 12 |
pub fn args() -> clap::Command { |
| 13 |
clap::command!("config") |
| 14 |
.args_override_self(true) |
| 15 |
.arg( |
| 16 |
Arg::new("name") |
| 17 |
.help("the section.name to print") |
| 18 |
.value_name("NAME") |
| 19 |
.required(true), |
| 20 |
) |
| 21 |
.about(HELP_TEXT) |
| 22 |
} |
| 23 |
|
| 24 |
pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> { |
| 25 |
let (section, name) = invocation |
| 26 |
.subcommand_args |
| 27 |
.get_one::<String>("name") |
| 28 |
.expect("missing required CLI argument") |
| 29 |
.as_bytes() |
| 30 |
.split_2(b'.') |
| 31 |
.ok_or_else(|| HgError::unsupported("hg config <section>"))?; |
| 32 |
|
| 33 |
if let Some(value) = invocation.config.get(section, name) { |
| 34 |
invocation.ui.write_stdout(&format_bytes!(b"{}\n", value))?; |
| 35 |
Ok(()) |
| 36 |
} else { |
| 37 |
Err(CommandError::Unsuccessful) |
| 38 |
} |
| 39 |
} |