1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-11-15 17:47:13 +00:00

fix(localip): disable localip module default (#3607)

This commit is contained in:
cubercsl 2022-02-14 22:51:29 +08:00 committed by GitHub
parent 32aca11c4a
commit efb16dd9ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,12 +11,18 @@ use crate::formatter::StringFormatter;
/// is to connect a UDP socket and then reading its local endpoint. /// is to connect a UDP socket and then reading its local endpoint.
/// ///
/// Will display the ip if all of the following criteria are met: /// Will display the ip if all of the following criteria are met:
/// - localip.disabled is absent or false /// - localip.disabled is false
/// - localip.ssh_only is false OR the user is currently connected as an SSH session (`$SSH_CONNECTION`) /// - localip.ssh_only is false OR the user is currently connected as an SSH session (`$SSH_CONNECTION`)
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("localip"); let mut module = context.new_module("localip");
let config: LocalipConfig = LocalipConfig::try_load(module.config); let config: LocalipConfig = LocalipConfig::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;
};
let ssh_connection = context.get_env("SSH_CONNECTION"); let ssh_connection = context.get_env("SSH_CONNECTION");
if config.ssh_only && ssh_connection.is_none() { if config.ssh_only && ssh_connection.is_none() {
return None; return None;
@ -86,6 +92,7 @@ mod tests {
.config(toml::toml! { .config(toml::toml! {
[localip] [localip]
ssh_only = false ssh_only = false
disabled = false
}) })
.collect(); .collect();
let expected = Some(format!("{} ", style().paint(localip))); let expected = Some(format!("{} ", style().paint(localip)));
@ -99,6 +106,7 @@ mod tests {
.config(toml::toml! { .config(toml::toml! {
[localip] [localip]
ssh_only = true ssh_only = true
disabled = false
}) })
.collect(); .collect();
let expected = None; let expected = None;
@ -114,6 +122,7 @@ mod tests {
[localip] [localip]
ssh_only = true ssh_only = true
trim_at = "" trim_at = ""
disabled = false
}) })
.env("SSH_CONNECTION", "something") .env("SSH_CONNECTION", "something")
.collect(); .collect();
@ -122,6 +131,16 @@ mod tests {
assert_eq!(expected, actual); assert_eq!(expected, actual);
} }
#[test]
fn config_blank() {
let actual = ModuleRenderer::new("localip")
.env("SSH_CONNECTION", "something")
.collect();
let expected = None;
assert_eq!(expected, actual);
}
fn style() -> Style { fn style() -> Style {
Color::Yellow.bold() Color::Yellow.bold()
} }