summaryrefslogtreecommitdiffstats
path: root/src/config.rs
diff options
context:
space:
mode:
authorMatan Kushner <hello@matchai.me>2019-07-31 19:48:51 -0400
committerMatan Kushner <hello@matchai.me>2019-08-05 11:05:08 -0400
commitf40f73dc8e26e6d8730344f4c6cbb47ee3d48342 (patch)
tree191bd072e71d4dc7662fc0a7e51637f4a2b291f8 /src/config.rs
parent616b50b4e31e1f057aebf2808bee3c72cc418594 (diff)
fix: Address longstanding linter errors
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs38
1 files changed, 16 insertions, 22 deletions
diff --git a/src/config.rs b/src/config.rs
index 92073b5f6..ba339468b 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -21,30 +21,27 @@ pub trait Config {
impl Config for Table {
/// Initialize the Config struct
fn initialize() -> Table {
- if let Some(file_data) = Table::config_from_file() {
+ if let Some(file_data) = Self::config_from_file() {
return file_data;
}
- Table::new()
+ Self::new()
}
/// Create a config from a starship configuration file
fn config_from_file() -> Option<Table> {
- let file_path = match env::var("STARSHIP_CONFIG") {
- Ok(path) => {
- // Use $STARSHIP_CONFIG as the config path if available
- log::debug!("STARSHIP_CONFIG is set: \n{}", &path);
- path
- }
- Err(_) => {
- // Default to using ~/.config/starhip.toml
- log::debug!("STARSHIP_CONFIG is not set");
- let config_path = home_dir()?.join(".config/starship.toml");
- let config_path_str = config_path.to_str()?.to_owned();
-
- log::debug!("Using default config path: {}", config_path_str);
- config_path_str
- }
+ let file_path = if let Ok(path) = env::var("STARSHIP_CONFIG") {
+ // Use $STARSHIP_CONFIG as the config path if available
+ log::debug!("STARSHIP_CONFIG is set: \n{}", &path);
+ path
+ } else {
+ // Default to using ~/.config/starhip.toml
+ log::debug!("STARSHIP_CONFIG is not set");
+ let config_path = home_dir()?.join(".config/starship.toml");
+ let config_path_str = config_path.to_str()?.to_owned();
+
+ log::debug!("Using default config path: {}", config_path_str);
+ config_path_str
};
let toml_content = match utils::read_file(&file_path) {
@@ -65,10 +62,7 @@ impl Config for Table {
/// Get the subset of the table for a module by its name
fn get_module_config(&self, module_name: &str) -> Option<&toml::value::Table> {
- let module_config = self
- .get(module_name)
- .map(toml::Value::as_table)
- .unwrap_or(None);
+ let module_config = self.get(module_name).and_then(toml::Value::as_table);
if module_config.is_some() {
log::debug!(
@@ -149,7 +143,7 @@ impl Config for Table {
}
}
-
+#[cfg(test)]
mod tests {
use super::*;