File tree Expand file tree Collapse file tree 2 files changed +6
-9
lines changed
Expand file tree Collapse file tree 2 files changed +6
-9
lines changed Original file line number Diff line number Diff line change @@ -188,11 +188,10 @@ impl Cli {
188188 }
189189
190190 let xdg_directories = Cli :: xdg_directories ( ) ?;
191+ // TODO (@Techassi): Move this file name to a constant
191192 let user_config_path = xdg_directories. config_dir ( ) . join ( "config.toml" ) ;
192193
193- let _user_config = UserConfig :: from_file ( user_config_path)
194- . unwrap ( )
195- . unwrap_or_default ( ) ;
194+ let _user_config = UserConfig :: from_file_or_default ( user_config_path) . unwrap ( ) ;
196195 dbg ! ( _user_config) ;
197196
198197 let cache = self
Original file line number Diff line number Diff line change @@ -29,18 +29,16 @@ pub enum Error {
2929}
3030
3131impl UserConfig {
32- pub fn from_file < P > ( path : P ) -> Result < Option < Self > , Error >
32+ /// Reads [`UserConfig`] from `path` or if not found, falls back to the default config.
33+ pub fn from_file_or_default < P > ( path : P ) -> Result < Self , Error >
3334 where
3435 P : AsRef < Path > ,
3536 {
3637 let path = path. as_ref ( ) ;
3738
3839 match std:: fs:: read_to_string ( path) {
39- Ok ( contents) => {
40- let config = toml:: from_str ( & contents) . context ( DeserializeSnafu { path } ) ?;
41- Ok ( Some ( config) )
42- }
43- Err ( err) if err. kind ( ) == std:: io:: ErrorKind :: NotFound => Ok ( None ) ,
40+ Ok ( contents) => toml:: from_str ( & contents) . context ( DeserializeSnafu { path } ) ,
41+ Err ( err) if err. kind ( ) == std:: io:: ErrorKind :: NotFound => Ok ( Self :: default ( ) ) ,
4442 Err ( err) => Err ( Error :: Read {
4543 path : path. to_path_buf ( ) ,
4644 source : err,
You can’t perform that action at this time.
0 commit comments