fix: Disable Kubernetes module by default (#488)

Given the global nature of the Kubernetes module, the module has been disabled by default. The opportunity has also been taken to refactor the Kubernetes module to use the new config module.
This commit is contained in:
Thomas O'Donnell
2019-10-05 11:31:23 +02:00
committed by Matan Kushner
parent 1bf60b3dd5
commit 5a8777ff45
4 changed files with 57 additions and 12 deletions
+34
View File
@@ -0,0 +1,34 @@
use crate::config::{ModuleConfig, RootModuleConfig, SegmentConfig};
use ansi_term::{Color, Style};
use starship_module_config_derive::ModuleConfig;
#[derive(Clone, ModuleConfig)]
pub struct KubernetesConfig<'a> {
pub symbol: SegmentConfig<'a>,
pub context: SegmentConfig<'a>,
pub namespace: SegmentConfig<'a>,
pub style: Style,
pub disabled: bool,
}
impl<'a> RootModuleConfig<'a> for KubernetesConfig<'a> {
fn new() -> Self {
KubernetesConfig {
symbol: SegmentConfig {
value: "",
style: None,
},
context: SegmentConfig {
value: "",
style: None,
},
namespace: SegmentConfig {
value: "",
style: None,
},
style: Color::Cyan.bold(),
disabled: true,
}
}
}
+1
View File
@@ -2,6 +2,7 @@ pub mod aws;
pub mod battery;
pub mod character;
pub mod dotnet;
pub mod kubernetes;
pub mod rust;
use crate::config::{ModuleConfig, RootModuleConfig};
+13 -10
View File
@@ -1,4 +1,3 @@
use ansi_term::Color;
use dirs;
use yaml_rust::YamlLoader;
@@ -6,9 +5,12 @@ use std::env;
use std::path;
use super::{Context, Module};
use crate::config::RootModuleConfig;
use crate::configs::kubernetes::KubernetesConfig;
use crate::utils;
const KUBE_CHAR: &str = " ";
const KUBERNETES_PREFIX: &str = "on ";
fn get_kube_context(contents: &str) -> Option<(String, String)> {
let yaml_docs = YamlLoader::load_from_str(&contents).ok()?;
@@ -50,17 +52,18 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let (kube_ctx, kube_ns) = kube_cfg;
let mut module = context.new_module("kubernetes");
let config: KubernetesConfig = KubernetesConfig::try_load(module.config);
let module_style = module
.config_value_style("style")
.unwrap_or_else(|| Color::Cyan.bold());
module.set_style(module_style);
module.get_prefix().set_value("on ");
module.set_style(config.style);
module.get_prefix().set_value(KUBERNETES_PREFIX);
module.new_segment("symbol", KUBE_CHAR);
module.new_segment("context", &kube_ctx);
module.create_segment("symbol", &config.symbol);
module.create_segment("context", &config.context.with_value(&kube_ctx));
if kube_ns != "" {
module.new_segment("namespace", &format!(" ({})", kube_ns));
module.create_segment(
"namespace",
&config.namespace.with_value(&format!(" ({})", kube_ns)),
);
}
Some(module)
}