Use implicit captured format args

This commit is contained in:
Jon Gjengset 2022-01-25 09:37:05 -08:00
parent 51917b450d
commit 02e071c630

View file

@ -1182,7 +1182,7 @@ impl Config {
// parse the value as a toml_edit::Document, and check that the (single)
// inner-most table is set via dotted keys.
let doc: toml_edit::Document = arg.parse().with_context(|| {
format!("failed to parse value from --config argument `{}` as a dotted key expression", arg)
format!("failed to parse value from --config argument `{arg}` as a dotted key expression")
})?;
fn non_empty_decor(d: &toml_edit::Decor) -> bool {
d.prefix().map_or(false, |p| !p.trim().is_empty())
@ -1204,26 +1204,23 @@ impl Config {
|| non_empty_decor(nt.decor())
{
bail!(
"--config argument `{}` \
includes non-whitespace decoration",
arg
"--config argument `{arg}` \
includes non-whitespace decoration"
)
}
table = nt;
}
Item::Value(v) if v.is_inline_table() => {
bail!(
"--config argument `{}` \
sets a value to an inline table, which is not accepted",
arg,
"--config argument `{arg}` \
sets a value to an inline table, which is not accepted"
);
}
Item::Value(v) => {
if non_empty_decor(v.decor()) {
bail!(
"--config argument `{}` \
includes non-whitespace decoration",
arg
"--config argument `{arg}` \
includes non-whitespace decoration"
)
}
got_to_value = true;
@ -1231,14 +1228,13 @@ impl Config {
}
Item::ArrayOfTables(_) => {
bail!(
"--config argument `{}` \
sets a value to an array of tables, which is not accepted",
arg,
"--config argument `{arg}` \
sets a value to an array of tables, which is not accepted"
);
}
Item::None => {
bail!("--config argument `{}` doesn't provide a value", arg)
bail!("--config argument `{arg}` doesn't provide a value")
}
}
}
@ -1246,17 +1242,16 @@ impl Config {
};
if !ok {
bail!(
"--config argument `{}` was not a TOML dotted key expression (such as `build.jobs = 2`)",
arg
"--config argument `{arg}` was not a TOML dotted key expression (such as `build.jobs = 2`)"
);
}
let toml_v = toml::from_document(doc).with_context(|| {
format!("failed to parse value from --config argument `{}`", arg)
format!("failed to parse value from --config argument `{arg}`")
})?;
CV::from_toml(Definition::Cli, toml_v)
.with_context(|| format!("failed to convert --config argument `{}`", arg))?
.with_context(|| format!("failed to convert --config argument `{arg}`"))?
};
let mut seen = HashSet::new();
let tmp_table = self
@ -1264,7 +1259,7 @@ impl Config {
.with_context(|| "failed to load --config include".to_string())?;
loaded_args
.merge(tmp_table, true)
.with_context(|| format!("failed to merge --config argument `{}`", arg))?;
.with_context(|| format!("failed to merge --config argument `{arg}`"))?;
}
Ok(loaded_args)
}