##// END OF EJS Templates
rust-dirstate: use a struct as arguments for the high-level `reset_state`...
rust-dirstate: use a struct as arguments for the high-level `reset_state` This makes the interface a lot clearer at the call site and prevents silly mistakes, as an API with a bunch of booleans is prone to errors. This refactor adds a `from_empty` parameter for a fast-path when resetting and entry we're sure does not exist. It will be used in the upcoming update Rust fastpath, and was not split to prevent more churn.

File last commit:

r50534:37bc3ede default
r52937:0cd16b1d default
Show More
config.rs
37 lines | 1.0 KiB | application/rls-services+xml | RustLexer
Simon Sapin
rhg: add limited support for the `config` sub-command...
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.
";
Raphaël Gomès
rhg: upgrade `clap` dependency...
r50534 pub fn args() -> clap::Command {
clap::command!("config")
Simon Sapin
rhg: add limited support for the `config` sub-command...
r47255 .arg(
Raphaël Gomès
rhg: upgrade `clap` dependency...
r50534 Arg::new("name")
Simon Sapin
rhg: add limited support for the `config` sub-command...
r47255 .help("the section.name to print")
.value_name("NAME")
Raphaël Gomès
rhg: upgrade `clap` dependency...
r50534 .required(true),
Simon Sapin
rhg: add limited support for the `config` sub-command...
r47255 )
.about(HELP_TEXT)
}
Simon Sapin
rhg: Group values passed to every sub-command into a struct...
r47334 pub fn run(invocation: &crate::CliInvocation) -> Result<(), CommandError> {
let (section, name) = invocation
.subcommand_args
Raphaël Gomès
rhg: upgrade `clap` dependency...
r50534 .get_one::<String>("name")
Simon Sapin
rhg: add limited support for the `config` sub-command...
r47255 .expect("missing required CLI argument")
.as_bytes()
.split_2(b'.')
Simon Sapin
rhg: Fall back to Python on unsupported `rhg config <section>`...
r47460 .ok_or_else(|| HgError::unsupported("hg config <section>"))?;
Simon Sapin
rhg: add limited support for the `config` sub-command...
r47255
Simon Sapin
rhg: Return an error code for `rhg config Section.idontexist`...
r47481 if let Some(value) = invocation.config.get(section, name) {
invocation.ui.write_stdout(&format_bytes!(b"{}\n", value))?;
Ok(())
} else {
Err(CommandError::Unsuccessful)
}
Simon Sapin
rhg: add limited support for the `config` sub-command...
r47255 }