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

View File

@ -574,13 +574,20 @@ can be done via `kubectl config set-context starship-cluster --namespace
astronaut`. If the `$KUBECONFIG` env var is set the module will use that if
not it will use the `~/.kube/config`.
::: tip
This module is disabled by default.
To enable it, set `disabled` to `false` in your configuration file.
:::
### Options
| Variable | Default | Description |
| ---------- | ------------- | --------------------------------------------------- |
| `symbol` | `"☸ "` | The symbol used before displaying the Cluster info. |
| `style` | `"bold blue"` | The style for the module. |
| `disabled` | `false` | Disables the `kubernetes` module |
| `disabled` | `true` | Disables the `kubernetes` module |
### Example
@ -590,7 +597,7 @@ not it will use the `~/.kube/config`.
[kubernetes]
symbol = "⛵ "
style = "dim green"
disabled = true
disabled = false
```

34
src/configs/kubernetes.rs Normal file
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,
}
}
}

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};

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)
}