@@ -24,22 +24,13 @@ impl Default for Config {
2424}
2525
2626impl Config {
27- pub fn new ( cli_args : & Cli ) -> anyhow:: Result < Self > {
27+ pub fn new ( config_files : & Vec < PathBuf > , _cli_args : & Cli ) -> anyhow:: Result < Self > {
2828 let mut builder = ConfigBuilder :: builder ( ) ;
2929
30- let xdg_config_file = dirs:: config_dir ( )
31- . map ( |p| p. join ( "debmagic" ) . join ( "config.toml" ) )
32- . ok_or ( anyhow ! ( "Could not determine user config directory" ) ) ?;
33- if xdg_config_file. is_file ( ) {
34- let xdg_config_file = xdg_config_file. to_str ( ) ;
35- if let Some ( xdg_config_file) = xdg_config_file {
36- builder = builder. add_source ( File :: with_name ( xdg_config_file) ) ;
37- }
30+ for file in config_files {
31+ builder = builder. add_source ( File :: with_name ( & file. to_string_lossy ( ) ) ) ;
3832 }
3933
40- if let Some ( config_override) = cli_args. config . as_ref ( ) . and_then ( |f| f. to_str ( ) ) {
41- builder = builder. add_source ( File :: with_name ( config_override) ) ;
42- }
4334 // TODO: reimplement cli arg overwrites
4435 let build = builder
4536 . build ( )
@@ -50,3 +41,27 @@ impl Config {
5041 config
5142 }
5243}
44+
45+ #[ cfg( test) ]
46+ mod tests {
47+ use crate :: cli:: Commands ;
48+
49+ use super :: * ;
50+
51+ #[ test]
52+ fn it_loads_a_simple_config ( ) -> Result < ( ) , anyhow:: Error > {
53+ let test_asset_dir = PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) )
54+ . join ( "tests" )
55+ . join ( "assets" ) ;
56+ let cfg = Config :: new (
57+ & vec ! [ test_asset_dir. join( "config1.toml" ) ] ,
58+ & Cli {
59+ config : None ,
60+ command : Commands :: Version { } ,
61+ } ,
62+ ) ?;
63+ assert ! ( cfg. dry_run) ;
64+
65+ Ok ( ( ) )
66+ }
67+ }
0 commit comments