1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-12-01 01:04:00 +00:00

fix: actually disable per default disabled modules (#1677)

The default `disabled: true` is actually only available within the module (when the config struct is used and not the user toml) but not all (the hg_branch) modules checked it there again.

Document this in all places and add the check (+ test) to the hg_branch module.
This commit is contained in:
Jan Katins 2020-09-26 09:35:41 +02:00 committed by GitHub
parent ffb1345052
commit c93bd7b705
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 39 additions and 0 deletions

View File

@ -18,6 +18,12 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let mut module = context.new_module("hg_branch"); let mut module = context.new_module("hg_branch");
let config: HgBranchConfig = HgBranchConfig::try_load(module.config); let config: HgBranchConfig = HgBranchConfig::try_load(module.config);
// As we default to disabled=true, we have to check here after loading our config module,
// before it was only checking against whatever is in the config starship.toml
if config.disabled {
return None;
};
// TODO: Once error handling is implemented, warn the user if their config // TODO: Once error handling is implemented, warn the user if their config
// truncation length is nonsensical // truncation length is nonsensical
let len = if config.truncation_length <= 0 { let len = if config.truncation_length <= 0 {
@ -125,6 +131,24 @@ mod tests {
repo_dir.close() repo_dir.close()
} }
#[test]
#[ignore]
fn test_hg_disabled_per_default() -> io::Result<()> {
let tempdir = fixture_repo(FixtureProvider::HG)?;
let repo_dir = tempdir.path();
run_hg(&["whatever", "blubber"], &repo_dir)?;
expect_hg_branch_with_config(
&repo_dir,
// no "disabled=false" in config!
Some(toml::toml! {
[hg_branch]
truncation_length = 14
}),
&[Expect::Empty],
)?;
tempdir.close()
}
#[test] #[test]
#[ignore] #[ignore]
fn test_hg_get_branch_fails() -> io::Result<()> { fn test_hg_get_branch_fails() -> io::Result<()> {
@ -186,6 +210,7 @@ mod tests {
Some(toml::toml! { Some(toml::toml! {
[hg_branch] [hg_branch]
truncation_length = 14 truncation_length = 14
disabled = false
}), }),
&[Expect::BranchName(&"branch-name-10")], &[Expect::BranchName(&"branch-name-10")],
)?; )?;
@ -215,6 +240,7 @@ mod tests {
symbol = "B " symbol = "B "
truncation_length = 14 truncation_length = 14
truncation_symbol = "%" truncation_symbol = "%"
disabled = false
}), }),
&[ &[
Expect::BranchName(&"branch-name-12"), Expect::BranchName(&"branch-name-12"),
@ -247,6 +273,7 @@ mod tests {
Some(toml::toml! { Some(toml::toml! {
[hg_branch] [hg_branch]
style = "underline blue" style = "underline blue"
disabled = false
}), }),
&[ &[
Expect::BranchName(&"branch-name-131"), Expect::BranchName(&"branch-name-131"),
@ -267,6 +294,7 @@ mod tests {
.config(config.unwrap_or_else(|| { .config(config.unwrap_or_else(|| {
toml::toml! { toml::toml! {
[hg_branch] [hg_branch]
disabled = false
} }
})) }))
.collect(); .collect();

View File

@ -58,6 +58,9 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let mut module = context.new_module("kubernetes"); let mut module = context.new_module("kubernetes");
let config: KubernetesConfig = KubernetesConfig::try_load(module.config); let config: KubernetesConfig = KubernetesConfig::try_load(module.config);
// As we default to disabled=true, we have to check here after loading our config module,
// before it was only checking against whatever is in the config starship.toml
if config.disabled { if config.disabled {
return None; return None;
}; };

View File

@ -33,6 +33,8 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
_ => "%", _ => "%",
}; };
// As we default to disabled=true, we have to check here after loading our config module,
// before it was only checking against whatever is in the config starship.toml
if config.disabled { if config.disabled {
return None; return None;
} }

View File

@ -12,6 +12,8 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let mut module = context.new_module("shlvl"); let mut module = context.new_module("shlvl");
let config: ShLvlConfig = ShLvlConfig::try_load(module.config); let config: ShLvlConfig = ShLvlConfig::try_load(module.config);
// As we default to disabled=true, we have to check here after loading our config module,
// before it was only checking against whatever is in the config starship.toml
if config.disabled || shlvl < config.threshold { if config.disabled || shlvl < config.threshold {
return None; return None;
} }
@ -45,6 +47,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
Some(module) Some(module)
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use ansi_term::{Color, Style}; use ansi_term::{Color, Style};

View File

@ -8,6 +8,9 @@ use crate::formatter::StringFormatter;
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let mut module = context.new_module("time"); let mut module = context.new_module("time");
let config: TimeConfig = TimeConfig::try_load(module.config); let config: TimeConfig = TimeConfig::try_load(module.config);
// As we default to disabled=true, we have to check here after loading our config module,
// before it was only checking against whatever is in the config starship.toml
if config.disabled { if config.disabled {
return None; return None;
}; };