summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatan Kushner <hello@matchai.me>2019-07-15 18:42:35 -0400
committerMatan Kushner <hello@matchai.me>2019-07-19 18:45:38 -0400
commitf7eedaf77574cf04afb8d3891b9070d9d6bdef9c (patch)
treeb3dd79395b4266d5d9e6db3ff1d02a8e36e952ef /src
parentfeb6d8aec7b95a71a1eb95b2eb3f4e9b39e99318 (diff)
refactor: Improve logging where lacking
Diffstat (limited to 'src')
-rw-r--r--src/config.rs59
-rw-r--r--src/modules/git_status.rs14
2 files changed, 66 insertions, 7 deletions
diff --git a/src/config.rs b/src/config.rs
index 4b28d69c5..f2045a688 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -24,7 +24,7 @@ impl Config {
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: {}", &path);
+ log::debug!("STARSHIP_CONFIG is set: \n{}", &path);
path
}
Err(_) => {
@@ -50,7 +50,7 @@ impl Config {
}?;
let config = toml::from_str(&toml_content).ok()?;
- log::debug!("Config found: \n{:?}", &config);
+ log::debug!("Config parsed: \n{:?}", &config);
Some(config)
}
@@ -61,26 +61,75 @@ impl Config {
.get(module_name)
.map(toml::Value::as_table)
.unwrap_or(None);
- log::debug!("Config found for {}: {:?}", &module_name, &module_config);
+
+ if module_config.is_some() {
+ log::debug!(
+ "Config found for \"{}\": \n{:?}",
+ &module_name,
+ &module_config
+ );
+ } else {
+ log::trace!("No config found for \"{}\"", &module_name);
+ }
+
module_config
}
}
/// Extends `toml::value::Table` with useful methods
pub trait TableExt {
+ fn get_config(&self, key: &str) -> Option<&toml::value::Value>;
fn get_as_bool(&self, key: &str) -> Option<bool>;
fn get_as_str(&self, key: &str) -> Option<&str>;
}
impl TableExt for toml::value::Table {
+ /// Get the config value for a given key
+ fn get_config(&self, key: &str) -> Option<&toml::value::Value> {
+ log::trace!("Looking for config key \"{}\"", key);
+ let config_value = self.get(key);
+
+ if config_value.is_some() {
+ log::trace!("Config found for \"{}\": {:?}", key, &config_value);
+ } else {
+ log::trace!("No value found for \"{}\"", key);
+ }
+
+ config_value
+ }
+
/// Get a key from a module's configuration as a boolean
fn get_as_bool(&self, key: &str) -> Option<bool> {
- self.get(key).map(toml::Value::as_bool).unwrap_or(None)
+ let value = self.get_config(key)?;
+ let bool_value = value.as_bool();
+
+ if bool_value.is_none() {
+ log::debug!(
+ "Expected \"{}\" to be a boolean. Instead received {} of type {}.",
+ key,
+ value,
+ value.type_str()
+ );
+ }
+
+ bool_value
}
/// Get a key from a module's configuration as a string
fn get_as_str(&self, key: &str) -> Option<&str> {
- self.get(key).map(toml::Value::as_str).unwrap_or(None)
+ let value = self.get_config(key)?;
+ let str_value = value.as_str();
+
+ if str_value.is_none() {
+ log::debug!(
+ "Expected \"{}\" to be a string. Instead received {} of type {}.",
+ key,
+ value,
+ value.type_str()
+ );
+ }
+
+ str_value
}
}
diff --git a/src/modules/git_status.rs b/src/modules/git_status.rs
index 912ce7d07..b56de3632 100644
--- a/src/modules/git_status.rs
+++ b/src/modules/git_status.rs
@@ -41,9 +41,19 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
module.set_style(module_style);
let ahead_behind = get_ahead_behind(&repository, &branch_name);
- log::debug!("Repo ahead/behind: {:?}", ahead_behind);
+ if ahead_behind != Ok((0, 0)) {
+ log::debug!("Repo ahead/behind: {:?}", ahead_behind);
+ } else {
+ log::trace!("No ahead/behind found");
+ }
+
let stash_object = repository.revparse_single("refs/stash");
- log::debug!("Stash object: {:?}", stash_object);
+ if stash_object.is_ok() {
+ log::debug!("Stash object: {:?}", stash_object);
+ } else {
+ log::trace!("No stash object found");
+ }
+
let repo_status = get_repo_status(&repository);
log::debug!("Repo status: {:?}", repo_status);