Skip to content

Commit

Permalink
fix #6; conifg type, no stderr if no sys config
Browse files Browse the repository at this point in the history
  • Loading branch information
tuna-f1sh committed Feb 11, 2023
1 parent dec5573 commit 3e70352
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = "List system USB buses and devices; a modern and compatible `lsusb
repository = "https://github.com/tuna-f1sh/cyme"
readme = "README.md"
license = "GPL-3.0-or-later"
version = "1.2.7"
version = "1.2.8"
edition = "2021"
keywords = ["usb", "lsusb", "system_profiler", "macos", "libusb"]
categories = ["command-line-utilities"]
Expand Down
8 changes: 6 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,22 @@ impl Config {
Ok(c)
}
Err(e) => {
// only return error it's not found as use default in that case
if e.kind() != io::ErrorKind::NotFound {
log::warn!(
"Failed to read cyme system config {:?}: Error({})",
&path,
e
);
Err(e)
} else {
Ok(Self::new())
}
Err(e)
}
};
} else {
Ok(Self::new())
}
Ok(Self::new())
}

/// Use default if running in debug since the integration tests use this
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,14 +407,14 @@ fn main() {
let config = Config::from_file(&path).unwrap_or_else(|e| {
eprintexit!(std::io::Error::new(
std::io::ErrorKind::Other,
format!("Failed to parse user conifg at {}: Error({})", path, e)
format!("Failed to parse user config at {}: Error({})", path, e)
));
});
log::info!("Using user config {:?}", config);
config
} else {
Config::sys().unwrap_or_else(|e| {
eprintln!("{}", format!("Failed to parse system conifg at {:?}, using default: Error({})", Config::config_file_path(), e).bold().red());
eprintln!("{}", format!("Failed to parse system config at {:?}, using default: Error({})", Config::config_file_path(), e).bold().red());
Config::new()
})
};
Expand Down

0 comments on commit 3e70352

Please sign in to comment.