Skip to content

Commit b7a714f

Browse files
committed
decouple construction of Config from ConfigLoader
1 parent 3c4fa04 commit b7a714f

File tree

2 files changed

+10
-21
lines changed

2 files changed

+10
-21
lines changed

src/application.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub(crate) use crate::application::app_data::AppData;
99
use crate::{
1010
Args,
1111
Exit,
12-
config::{Config, ConfigLoader, DiffIgnoreWhitespaceSetting},
12+
config::{Config, ConfigError, ConfigErrorCause, ConfigLoader, DiffIgnoreWhitespaceSetting},
1313
diff::{self, CommitDiffLoader, CommitDiffLoaderOptions},
1414
display::Display,
1515
git::open_repository_from_env,
@@ -42,7 +42,8 @@ where ModuleProvider: module::ModuleProvider + Send + 'static
4242
let filepath = Self::filepath_from_args(args)?;
4343
let repository = Self::open_repository()?;
4444
let config_loader = ConfigLoader::from(repository);
45-
let config = Self::load_config(&config_loader)?;
45+
let config = Self::load_config(&config_loader)
46+
.map_err(|err| Exit::new(ExitStatus::ConfigError, format!("{err:#}").as_str()))?;
4647
let todo_file = Arc::new(Mutex::new(Self::load_todo_file(filepath.as_str(), &config)?));
4748

4849
let display = Display::new(tui, &config.theme);
@@ -162,8 +163,11 @@ where ModuleProvider: module::ModuleProvider + Send + 'static
162163
})
163164
}
164165

165-
fn load_config(config_loader: &ConfigLoader) -> Result<Config, Exit> {
166-
Config::try_from(config_loader).map_err(|err| Exit::new(ExitStatus::ConfigError, format!("{err:#}").as_str()))
166+
fn load_config(config_loader: &ConfigLoader) -> Result<Config, ConfigError> {
167+
let config = config_loader
168+
.load_config()
169+
.map_err(|e| ConfigError::new_read_error("", ConfigErrorCause::GitError(e)))?;
170+
Config::new_with_config(Some(&config))
167171
}
168172

169173
fn todo_file_options(config: &Config) -> TodoFileOptions {

src/config.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,6 @@ impl Config {
9494
}
9595
}
9696

97-
impl TryFrom<&ConfigLoader> for Config {
98-
type Error = ConfigError;
99-
100-
/// Creates a new Config instance loading the Git Config.
101-
///
102-
/// # Errors
103-
///
104-
/// Will return an `Err` if there is a problem loading the configuration.
105-
fn try_from(config_loader: &ConfigLoader) -> Result<Self, Self::Error> {
106-
let config = config_loader
107-
.load_config()
108-
.map_err(|e| ConfigError::new_read_error("", ConfigErrorCause::GitError(e)))?;
109-
Self::new_with_config(Some(&config))
110-
}
111-
}
112-
11397
impl TryFrom<&crate::git::Config> for Config {
11498
type Error = ConfigError;
11599

@@ -132,7 +116,8 @@ mod tests {
132116
fn try_from_config_loader() {
133117
with_temp_bare_repository(|repository| {
134118
let loader = ConfigLoader::from(repository);
135-
assert_ok!(Config::try_from(&loader));
119+
let config = assert_ok!(loader.load_config());
120+
assert_ok!(Config::try_from(&config));
136121
});
137122
}
138123

0 commit comments

Comments
 (0)