Skip to content

Commit be6ecad

Browse files
committed
config: allow config path to be a dir or a file
For dir, as before, the mail and state dirs default to the config dir. For file, the defaults will be computed per previous commit.
1 parent a785434 commit be6ecad

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/config.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,12 @@ fn default_convert_dos_to_unix() -> bool {
276276
}
277277

278278
impl Config {
279-
pub fn from_dir(path: &PathBuf) -> Result<Self> {
280-
let filename = path.join("mujmap.toml");
279+
pub fn from_path(path: &PathBuf) -> Result<Self> {
280+
let filename = if path.is_dir() {
281+
path.join("mujmap.toml")
282+
} else {
283+
path.clone()
284+
};
281285

282286
let contents = fs::read_to_string(&filename).context(ReadConfigFileSnafu {
283287
filename: filename.clone(),
@@ -287,11 +291,13 @@ impl Config {
287291
})?;
288292

289293
// In directory mode, if paths aren't offered then we use the config dir itself.
290-
if config.mail_dir.is_none() {
291-
config.mail_dir = Some(path.clone());
292-
}
293-
if config.state_dir.is_none() {
294-
config.state_dir = Some(path.clone());
294+
if path.is_dir() {
295+
if config.mail_dir.is_none() {
296+
config.mail_dir = Some(path.clone());
297+
}
298+
if config.state_dir.is_none() {
299+
config.state_dir = Some(path.clone());
300+
}
295301
}
296302

297303
// Perform final validation.

src/main.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ fn try_main(stdout: &mut StandardStream) -> Result<(), Error> {
6161
.to_owned();
6262

6363
// Determine working directory and load all data files.
64-
let config_dir = args.path.clone().unwrap_or_else(|| PathBuf::from("."));
65-
66-
let config = Config::from_dir(&config_dir).context(OpenConfigFileSnafu {})?;
64+
let config_path = args.path.clone().unwrap_or_else(|| PathBuf::from("."));
65+
let config = Config::from_path(&config_path).context(OpenConfigFileSnafu {})?;
6766
debug!("Using config: {:?}", config);
6867

6968
match args.command {

0 commit comments

Comments
 (0)