@@ -184,21 +184,29 @@ func validArgs() {
184
184
}
185
185
}
186
186
187
+ // loadConfig loads config from config file to xapp.AppCfg
187
188
func loadConfig (cfg * xapp.Config ) {
188
189
189
190
homeDir , err := os .UserHomeDir ()
190
191
xlog .AbortErr (err )
191
192
192
193
appDir := xpath .MustGetApplicationPath ("" )
193
194
194
- var configFiles = [] string {
195
- filepath .Join (homeDir , ".upgit.config.toml" ),
196
- filepath .Join (homeDir , ".upgit.toml" ),
197
- filepath .Join (appDir , "config.toml" ),
195
+ var configFiles = map [ string ] bool {
196
+ filepath .Join (homeDir , ".upgit.config.toml" ): false ,
197
+ filepath .Join (homeDir , ".upgit.toml" ): false ,
198
+ filepath .Join (appDir , "config.toml" ): false ,
198
199
}
199
200
200
- for _ , configFile := range configFiles {
201
+ if xapp .AppOpt .ConfigFile != "" {
202
+ configFiles [xapp .AppOpt .ConfigFile ] = true
203
+ }
204
+
205
+ for configFile , required := range configFiles {
201
206
if _ , err := os .Stat (configFile ); err != nil {
207
+ if required {
208
+ xlog .AbortErr (fmt .Errorf ("config file %s not found" , configFile ))
209
+ }
202
210
continue
203
211
}
204
212
optRawBytes , err := ioutil .ReadFile (configFile )
@@ -212,6 +220,10 @@ func loadConfig(cfg *xapp.Config) {
212
220
break
213
221
}
214
222
223
+ if xapp .ConfigFilePath == "" {
224
+ xlog .AbortErr (fmt .Errorf ("no config file found" ))
225
+ }
226
+
215
227
// fill config
216
228
xapp .AppCfg .Rename = strings .Trim (xapp .AppCfg .Rename , "/" )
217
229
xapp .AppCfg .Rename = xstrings .RemoveFmtUnderscore (xapp .AppCfg .Rename )
0 commit comments