[Enhancement] Read config file from platform-specific config folder (#839)

* read config file from platform-specific config folder

* Update src/input.rs

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: Autumn (Bee) <[email protected]>
Co-authored-by: Copilot <[email protected]>
This commit is contained in:
authored and GitHub committed 2025-11-27 10:50:14 +09:00
1 parent a40c4ed17f
commit 4c056a9039
2 files changed
+28 -1

No files matched your search

+17 -1
View File
@@ -294,7 +294,14 @@ impl Config {
///
pub fn read(custom_config_path: Option<PathBuf>) -> Self {
let mut content = String::new();
let config_path = custom_config_path.unwrap_or_else(default_config_path);
let config_path = custom_config_path.unwrap_or_else(|| {
let path = default_config_path();
match path.exists() {
true => path,
false => old_default_config_path(),
}
});
if config_path.exists() {
content = match fs::read_to_string(config_path) {
Ok(content) => content,
@@ -316,6 +323,15 @@ impl Config {
/// Constructs default path to config toml
pub fn default_config_path() -> PathBuf {
let Some(mut config_path) = dirs::config_dir() else {
panic!("Could not infer config file path.");
};
config_path.push(".rustscan.toml");
config_path
}
/// Returns the deprecated home directory config path used for backwards compatibility.
pub fn old_default_config_path() -> PathBuf {
let Some(mut config_path) = dirs::home_dir() else {
panic!("Could not infer config file path.");
};
+11
View File
@@ -219,6 +219,17 @@ The Modern Day Port Scanner."#;
opts.greppable,
opts.accessible
);
if opts.config_path.is_none() {
let old_config_path = input::old_default_config_path();
detail!(
format!(
"For backwards compatibility, the config file may also be at {old_config_path:?}"
),
opts.greppable,
opts.accessible
);
}
}
#[cfg(unix)]