Skip to content

Commit a876500

Browse files
committed
Fix --config-file being searched as a directory
1 parent a646f0b commit a876500

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
- Lexing of conditional directive expressions containing compiler directives, comments, or strings.
1717
- Lexing of compiler directives similar to conditional directives (e.g. `{$if_}`).
1818
- Lexing of unterminated asm text literals at EOF.
19+
- `--config-file` no longer erroneously accepts a path to a directory and searches from it for a
20+
`pasfmt.toml` file. It is now an error to provide a path to a directory.
1921

2022
## [0.3.0] - 2024-05-29
2123

orchestrator/src/command_line.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{borrow::Cow, error::Error, fs::read_to_string, path::PathBuf, str::FromStr};
22

33
use anstyle::AnsiColor;
4-
use anyhow::Context;
4+
use anyhow::{bail, Context};
55
pub use clap::{self, error::ErrorKind, CommandFactory, Parser};
66
use clap::{
77
builder::PossibleValuesParser, builder::Styles, builder::TypedValueParser, Args, ValueEnum,
@@ -212,9 +212,17 @@ impl PasFmtConfiguration {
212212
// canonicalize it. We do want the default config path to be searched for in parent
213213
// directories, so that path is left relative.
214214
let config_file = match &self.config_file {
215-
Some(file) => file.canonicalize().with_context(|| {
216-
format!("Failed to resolve config file path: '{}'", file.display())
217-
})?,
215+
Some(file) => {
216+
if file.is_dir() {
217+
bail!(
218+
"Config file path cannot be a directory: '{}'",
219+
file.display()
220+
);
221+
}
222+
file.canonicalize().with_context(|| {
223+
format!("Failed to resolve config file path: '{}'", file.display())
224+
})?
225+
}
218226
None => PathBuf::from(DEFAULT_CONFIG_FILE_NAME),
219227
};
220228
debug!("Using config file: {}", config_file.display());

0 commit comments

Comments
 (0)