Change with_toml_strings to incorporate_toml_string

It makes more sense for this function to change `self`.
This commit is contained in:
Ilya Grigoriev 2023-01-01 16:54:10 -08:00
parent 95637e252c
commit e8b21c5ce0
2 changed files with 8 additions and 10 deletions

View File

@ -45,21 +45,18 @@ impl UserSettings {
UserSettings { config, timestamp } UserSettings { config, timestamp }
} }
pub fn with_toml_strings( pub fn incorporate_toml_strings(
&self, &mut self,
toml_strs: &[String], toml_strs: &[String],
) -> Result<UserSettings, config::ConfigError> { ) -> Result<(), config::ConfigError> {
let mut config_builder = config::Config::builder().add_source(self.config.clone()); let mut config_builder = config::Config::builder().add_source(self.config.clone());
for s in toml_strs { for s in toml_strs {
config_builder = config_builder =
config_builder.add_source(config::File::from_str(s, config::FileFormat::Toml)); config_builder.add_source(config::File::from_str(s, config::FileFormat::Toml));
} }
let new_config = config_builder.build()?; self.config = config_builder.build()?;
let timestamp = get_timestamp_config(&new_config, "user.timestamp"); self.timestamp = get_timestamp_config(&self.config, "user.timestamp");
Ok(UserSettings { Ok(())
config: new_config,
timestamp,
})
} }
pub fn with_repo(&self, repo_path: &Path) -> Result<RepoSettings, config::ConfigError> { pub fn with_repo(&self, repo_path: &Path) -> Result<RepoSettings, config::ConfigError> {

View File

@ -1590,7 +1590,8 @@ fn handle_early_args(
ui.set_pagination(crate::ui::PaginationChoice::No); ui.set_pagination(crate::ui::PaginationChoice::No);
} }
if !args.config_toml.is_empty() { if !args.config_toml.is_empty() {
let settings = ui.settings().with_toml_strings(&args.config_toml)?; let mut settings = ui.settings().clone();
settings.incorporate_toml_strings(&args.config_toml)?;
ui.reset(settings); ui.reset(settings);
} }
Ok(()) Ok(())