Skip to content

Commit

Permalink
Merge pull request #26 from tofubert/fix/config_calling_exit
Browse files Browse the repository at this point in the history
make config init not call exit
  • Loading branch information
tofubert authored Aug 29, 2024
2 parents 80578ae + c469909 commit 75b8101
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct Config {
strategy: Xdg,
}

pub fn init(path_arg: &str) {
pub fn init(path_arg: &str) -> Result<(), Box<dyn std::error::Error>> {
let strategy = choose_app_strategy(AppStrategyArgs {
top_level_domain: "org".to_string(),
author: "emlix".to_string(),
Expand Down Expand Up @@ -70,7 +70,7 @@ pub fn init(path_arg: &str) {
.expect("Failed to make config path into string")
);
Data::to_toml_example(example_config_path.as_os_str().to_str().unwrap()).unwrap();
exit(-1);
return Err(Box::new(why));
}
};

Expand All @@ -81,6 +81,7 @@ pub fn init(path_arg: &str) {
.set(config)
.map_err(|config| eyre!("failed to set config {config:?}"))
.expect("Could not set global config!");
Ok(())
}

/// Get the application configuration.
Expand Down Expand Up @@ -212,12 +213,12 @@ mod tests {
expected = "Could not Create Config dir: Os { code: 13, kind: PermissionDenied, message: \"Permission denied\" }"
)]
fn init_with_faulty_path() {
init("/bogus_test/path");
assert!(init("/bogus_test/path").is_err());
}

#[test]
fn default_values() {
init("./test/");
assert!(init("./test/").is_ok());
assert!(get().get_data_dir().ends_with(".local/share/sechat-rs"));
assert!(get()
.get_server_data_dir()
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct Args {
async fn main() {
let args = Args::parse();

config::init(&args.config_path);
config::init(&args.config_path).expect("Config init aborted.");
config::get().config_logging();

// check if crate has alpha suffix in version
Expand Down

0 comments on commit 75b8101

Please sign in to comment.