Show More
@@ -1,36 +1,36 b'' | |||||
1 | use crate::error::CommandError; |
|
1 | use crate::error::CommandError; | |
2 | use clap::Arg; |
|
2 | use clap::Arg; | |
3 | use format_bytes::format_bytes; |
|
3 | use format_bytes::format_bytes; | |
4 | use hg::errors::HgError; |
|
4 | use hg::errors::HgError; | |
5 | use hg::utils::SliceExt; |
|
5 | use hg::utils::SliceExt; | |
6 |
|
6 | |||
7 | pub const HELP_TEXT: &str = " |
|
7 | pub const HELP_TEXT: &str = " | |
8 | With one argument of the form section.name, print just the value of that config item. |
|
8 | With one argument of the form section.name, print just the value of that config item. | |
9 | "; |
|
9 | "; | |
10 |
|
10 | |||
11 | pub fn args() -> clap::App<'static, 'static> { |
|
11 | pub fn args() -> clap::App<'static, 'static> { | |
12 | clap::SubCommand::with_name("config") |
|
12 | clap::SubCommand::with_name("config") | |
13 | .arg( |
|
13 | .arg( | |
14 | Arg::with_name("name") |
|
14 | Arg::with_name("name") | |
15 | .help("the section.name to print") |
|
15 | .help("the section.name to print") | |
16 | .value_name("NAME") |
|
16 | .value_name("NAME") | |
17 | .required(true) |
|
17 | .required(true) | |
18 | .takes_value(true), |
|
18 | .takes_value(true), | |
19 | ) |
|
19 | ) | |
20 | .about(HELP_TEXT) |
|
20 | .about(HELP_TEXT) | |
21 | } |
|
21 | } | |
22 |
|
22 | |||
23 | pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> { |
|
23 | pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> { | |
24 | let (section, name) = invocation |
|
24 | let (section, name) = invocation | |
25 | .subcommand_args |
|
25 | .subcommand_args | |
26 | .value_of("name") |
|
26 | .value_of("name") | |
27 | .expect("missing required CLI argument") |
|
27 | .expect("missing required CLI argument") | |
28 | .as_bytes() |
|
28 | .as_bytes() | |
29 | .split_2(b'.') |
|
29 | .split_2(b'.') | |
30 |
.ok_or_else(|| HgError:: |
|
30 | .ok_or_else(|| HgError::unsupported("hg config <section>"))?; | |
31 |
|
31 | |||
32 | let value = invocation.config.get(section, name).unwrap_or(b""); |
|
32 | let value = invocation.config.get(section, name).unwrap_or(b""); | |
33 |
|
33 | |||
34 | invocation.ui.write_stdout(&format_bytes!(b"{}\n", value))?; |
|
34 | invocation.ui.write_stdout(&format_bytes!(b"{}\n", value))?; | |
35 | Ok(()) |
|
35 | Ok(()) | |
36 | } |
|
36 | } |
General Comments 0
You need to be logged in to leave comments.
Login now