duplicate config check, change default config if Windows
This commit is contained in:
parent
03aef02abc
commit
d7a84d5471
2 changed files with 27 additions and 4 deletions
|
@ -118,15 +118,30 @@ pub fn read_config(paths: Vec<PathBuf>, refractr: &common::Refractr) -> Vec<Conf
|
|||
}
|
||||
|
||||
let config_file = ConfigFile {
|
||||
path: String::from(path.to_string_lossy()),
|
||||
path: match fs::canonicalize(&path) {
|
||||
Err(_) => panic!("refractr: cannot get absolute path of config file: {}", path.as_path().display()),
|
||||
Ok(abs) => abs.to_string_lossy().to_string()
|
||||
},
|
||||
file: match fs::metadata(&path) {
|
||||
Err(_) => panic!("refractr: cannot obtain metadata: {}", path.as_path().display()),
|
||||
Err(_) => panic!("refractr: cannot obtain metadata for config file: {}", path.as_path().display()),
|
||||
Ok(metadata) => metadata
|
||||
},
|
||||
config: verify_config(toml::from_str(&data).unwrap())
|
||||
};
|
||||
|
||||
config_files.push(config_file);
|
||||
let mut dup = false;
|
||||
for i in &config_files {
|
||||
if i.path == config_file.path {
|
||||
eprintln!("refractr: warning: skipping config file \"{}\" as it was already read", path.as_path().display());
|
||||
dup = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if !dup {
|
||||
config_files.push(config_file);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return config_files;
|
||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -11,7 +11,7 @@ use std::process;
|
|||
#[command(about = "An automated push/pull/clone utility for mirroring Git repositories")]
|
||||
#[command(long_about = None)]
|
||||
struct Args {
|
||||
#[arg(short, long, help = "Specify a config file", default_value = "/etc/refractr/config.toml")]
|
||||
#[arg(short, long, help = "Specify a config file", default_value = get_config_default())]
|
||||
config: Vec<PathBuf>,
|
||||
|
||||
#[arg(short, long, help = "Specify the level of verbosity", action = clap::ArgAction::Count)]
|
||||
|
@ -21,6 +21,14 @@ struct Args {
|
|||
create: bool,
|
||||
}
|
||||
|
||||
fn get_config_default() -> &'static str {
|
||||
if cfg!(windows) {
|
||||
"C:\\ProgramData\\refractr\\config.toml"
|
||||
} else {
|
||||
"/etc/refractr/config.toml"
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = Args::parse();
|
||||
let refractr = common::Refractr {
|
||||
|
|
Loading…
Add table
Reference in a new issue