Skip to content
Open
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6ad27f6
✨feat: `selene.toml` and `.selene.toml` are not detected by order of …
Zeioth Mar 10, 2024
02213f4
🐛fix(`.selene`): has now order of precedence over `selene.toml`.
Zeioth Mar 13, 2024
b4a93e3
🐛fix(error!): instead of eprintln.
Zeioth Mar 13, 2024
13e6286
♻️refactor(read_config_file): Is now a function.
Zeioth Mar 13, 2024
9e91ded
Update selene/src/main.rs
Zeioth Mar 15, 2024
de9aa79
fix: Terminate the process when config file is invalid.
Zeioth Mar 17, 2024
8947dea
fix: We now check that the file exist. Also we only raise a error if …
Zeioth Mar 18, 2024
406558f
fix(regression): Ensure it fallback on the default config.
Zeioth Mar 18, 2024
f7785fb
refactor of the former
Zeioth Mar 18, 2024
5def22b
♻️refactor: All should be fine now, but we can still refactor the fun…
Zeioth Mar 18, 2024
69d6d98
♻️refactor: All config file detection logic has been moved to functions.
Zeioth Mar 18, 2024
64bbb82
comments: More consistent.
Zeioth Mar 18, 2024
d0cb38e
Update CHANGELOG.md
Zeioth Mar 18, 2024
e5fd4f0
docs: updated for `.selene.toml`.
Zeioth Mar 18, 2024
d7de32e
Merge remote-tracking branch 'refs/remotes/origin/dot-selene-toml'
Zeioth Mar 18, 2024
1c425b8
fix(comments): Our comments were preventing `cargo rustdoc` from runn…
Zeioth Mar 18, 2024
0ef6e80
Update selene/src/main.rs
Zeioth Mar 26, 2024
ef996c4
Update selene/src/main.rs
Zeioth Mar 26, 2024
822bc44
refactor: config_paths_to_check is now a constant.
Zeioth Mar 26, 2024
ade463c
refactor: read_config_file() -> (String, Option<PathBuf>) the type re…
Zeioth Mar 27, 2024
3812d6b
refactor: Now that we handle the bad utf-8 error correctly, let's add…
Zeioth Mar 27, 2024
47b0642
vscode: relevant changes to vscode extension.
Zeioth Mar 27, 2024
4ca19d4
♻️refactor: We now let rust manage the invalid UTF-8 error instead of…
Zeioth May 7, 2024
aff6f9a
🐛fix(config file detection): If path exists and fs::read_to_string er…
Zeioth May 8, 2024
7c844a3
🐛refactor: There is no need for us to explicitely read the file as ut…
Zeioth May 8, 2024
5c02fe9
comments: Better info, in case we decide to enable this.
Zeioth May 8, 2024
9829822
fix: The error now works as originally intended → `ERROR: Error readi…
Zeioth May 21, 2024
ed5e764
Update main.rs → comments
Zeioth May 21, 2024
7fa7825
fix: Display the next error ONLY on validate-config → `ERROR: Error r…
Zeioth May 21, 2024
8817d13
Solve merge conflict
Zeioth May 21, 2024
04ed488
Merge branch 'main' into dot-selene-toml
chriscerie Jun 29, 2024
dcf3458
Refactor
chriscerie Jun 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 37 additions & 18 deletions selene/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,15 +412,28 @@ fn start(mut options: opts::Options) {

(config_contents, Path::new("-"))
} else {
let config_path = Path::new("selene.toml");

let config_contents = match fs::read_to_string(config_path) {
Ok(contents) => contents,
Err(error) => {
error!("Error reading config file: {error}");
std::process::exit(1);
let config_paths_to_check = [Path::new("selene.toml"), Path::new(".selene.toml")];
let mut config_contents = String::new();
let mut config_path = Path::new("");
let mut config_not_found = true;

for path in &config_paths_to_check {
match fs::read_to_string(path) {
Ok(contents) => {
config_contents = contents;
config_path = path;
config_not_found = false;
break;
}
Err(error) => {
error!("Error reading config file: {error}");
}
}
};
}

if config_not_found {
std::process::exit(1);
}

(config_contents, config_path)
};
Expand Down Expand Up @@ -517,17 +530,23 @@ fn start(mut options: opts::Options) {
}
}

None => match fs::read_to_string("selene.toml") {
Ok(config_contents) => match toml::from_str(&config_contents) {
Ok(config) => (config, None),
Err(error) => {
error!("Config file not in correct format: {}", error);
std::process::exit(1);
}
},
None => {
let read_config_file = |file: &str| -> Option<CheckerConfig<toml::value::Value>> {
let config_contents = fs::read_to_string(file).ok()?;
toml::from_str(&config_contents)
.map_err(|error| {
eprintln!("Error parsing config file {}: {}", file, error);
error
})
.ok()
};

Err(_) => (CheckerConfig::default(), None),
},
let config = read_config_file("selene.toml")
.or_else(|| read_config_file(".selene.toml"))
.unwrap_or_else(|| CheckerConfig::default());

(config, None)
}
};

let current_dir = std::env::current_dir().unwrap();
Expand Down