@@ -3,11 +3,18 @@ use errors::*;
3
3
use regex:: Regex ;
4
4
use serde_regex;
5
5
use std:: collections:: { HashMap , HashSet } ;
6
+ use std:: env;
7
+ use std:: ffi:: OsStr ;
6
8
use std:: fs:: File ;
7
9
use std:: io:: Read ;
10
+ use std:: path:: PathBuf ;
8
11
use utils:: size:: Size ;
9
12
10
- static CONFIG_FILE : & ' static str = "config.toml" ;
13
+ fn default_config_file ( ) -> PathBuf {
14
+ env:: var_os ( "CRATER_CONFIG" )
15
+ . unwrap_or_else ( || OsStr :: new ( "config.toml" ) . to_os_string ( ) )
16
+ . into ( )
17
+ }
11
18
12
19
#[ derive( Clone , Serialize , Deserialize ) ]
13
20
#[ serde( rename_all = "kebab-case" ) ]
@@ -69,12 +76,12 @@ pub struct Config {
69
76
70
77
impl Config {
71
78
pub fn load ( ) -> Result < Self > {
72
- let buffer = Self :: load_as_string ( CONFIG_FILE ) ?;
79
+ let buffer = Self :: load_as_string ( default_config_file ( ) ) ?;
73
80
74
81
Ok ( :: toml:: from_str ( & buffer) ?)
75
82
}
76
83
77
- fn load_as_string ( filename : & str ) -> Result < String > {
84
+ fn load_as_string ( filename : PathBuf ) -> Result < String > {
78
85
let mut buffer = String :: new ( ) ;
79
86
File :: open ( filename) ?. read_to_string ( & mut buffer) ?;
80
87
@@ -117,13 +124,13 @@ impl Config {
117
124
118
125
pub fn check ( file : & Option < String > ) -> Result < ( ) > {
119
126
if let Some ( file) = file {
120
- Self :: check_all ( & file)
127
+ Self :: check_all ( file. into ( ) )
121
128
} else {
122
- Self :: check_all ( CONFIG_FILE )
129
+ Self :: check_all ( default_config_file ( ) )
123
130
}
124
131
}
125
132
126
- fn check_all ( filename : & str ) -> Result < ( ) > {
133
+ fn check_all ( filename : PathBuf ) -> Result < ( ) > {
127
134
use experiments:: CrateSelect ;
128
135
129
136
let buffer = Self :: load_as_string ( filename) ?;
0 commit comments