mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-19 10:44:58 +00:00
cli: set global args to config table without re-parsing as TOML
This should be safer than constructing a parsable TOML form.
This commit is contained in:
parent
e1ab2477cd
commit
c29b5a2aa3
2 changed files with 20 additions and 6 deletions
|
@ -3276,19 +3276,28 @@ fn handle_early_args(
|
|||
)
|
||||
.ignore_errors(true)
|
||||
.try_get_matches_from(args)?;
|
||||
let mut args: EarlyArgs = EarlyArgs::from_arg_matches(&early_matches).unwrap();
|
||||
let args = EarlyArgs::from_arg_matches(&early_matches).unwrap();
|
||||
|
||||
let old_layers_len = config.layers().len();
|
||||
config.extend_layers(parse_config_args(&args.config_toml)?);
|
||||
|
||||
// Command arguments overrides any other configuration including the
|
||||
// variables loaded from --config* arguments.
|
||||
let mut layer = ConfigLayer::empty(ConfigSource::CommandArg);
|
||||
if let Some(choice) = args.color {
|
||||
args.config_toml.push(format!(r#"ui.color="{choice}""#));
|
||||
layer.set_value("ui.color", choice.to_string()).unwrap();
|
||||
}
|
||||
if args.quiet.unwrap_or_default() {
|
||||
args.config_toml.push(r#"ui.quiet=true"#.to_string());
|
||||
layer.set_value("ui.quiet", true).unwrap();
|
||||
}
|
||||
if args.no_pager.unwrap_or_default() {
|
||||
args.config_toml.push(r#"ui.paginate="never""#.to_owned());
|
||||
layer.set_value("ui.paginate", "never").unwrap();
|
||||
}
|
||||
if !args.config_toml.is_empty() {
|
||||
config.extend_layers(parse_config_args(&args.config_toml)?);
|
||||
if !layer.is_empty() {
|
||||
config.add_layer(layer);
|
||||
}
|
||||
|
||||
if config.layers().len() != old_layers_len {
|
||||
ui.reset(config)?;
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
@ -327,6 +327,11 @@ impl ConfigLayer {
|
|||
.try_collect()
|
||||
}
|
||||
|
||||
/// Returns true if the table has no configuration variables.
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.data.is_empty()
|
||||
}
|
||||
|
||||
// Add .get_value(name) if needed. look_up_*() are low-level API.
|
||||
|
||||
/// Looks up sub non-inline table by the `name` path. Returns `Some(table)`
|
||||
|
|
Loading…
Reference in a new issue