From e38be5073fd09ec1b199c6d542d34a7f76e3d5fd Mon Sep 17 00:00:00 2001 From: sk1985 <36002659+stku1985@users.noreply.github.com> Date: Fri, 3 Apr 2020 20:18:44 +0200 Subject: [PATCH] feat(kubernetes): context aliases (#1015) * Allow kubernetes module to use aliases for contexts * documentation for kubernetes context aliasing * Apply suggestions from code review: consistent ordering of options in documentation Co-Authored-By: Thomas O'Donnell Co-authored-by: Thomas O'Donnell --- docs/config/README.md | 13 ++++++++----- src/configs/kubernetes.rs | 3 +++ src/modules/kubernetes.rs | 8 +++++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/docs/config/README.md b/docs/config/README.md index 8dec600a..3042691d 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -836,11 +836,12 @@ 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` | `true` | Disables the `kubernetes` module | +| Variable | Default | Description | +| ---------------- | ------------- | --------------------------------------------------- | +| `symbol` | `"☸ "` | The symbol used before displaying the Cluster info. | +| `context_aliases` | | Table of context aliases to display | +| `style` | `"bold blue"` | The style for the module. | +| `disabled` | `true` | Disables the `kubernetes` module | ### Example @@ -851,6 +852,8 @@ To enable it, set `disabled` to `false` in your configuration file. symbol = "⛵ " style = "dimmed green" disabled = false +[kubernetes.context_aliases] +"dev.local.cluster.k8s" = "dev" ``` ## Line Break diff --git a/src/configs/kubernetes.rs b/src/configs/kubernetes.rs index 2d8e681b..bc28cddd 100644 --- a/src/configs/kubernetes.rs +++ b/src/configs/kubernetes.rs @@ -2,6 +2,7 @@ use crate::config::{ModuleConfig, RootModuleConfig, SegmentConfig}; use ansi_term::{Color, Style}; use starship_module_config_derive::ModuleConfig; +use std::collections::HashMap; #[derive(Clone, ModuleConfig)] pub struct KubernetesConfig<'a> { @@ -10,6 +11,7 @@ pub struct KubernetesConfig<'a> { pub namespace: SegmentConfig<'a>, pub style: Style, pub disabled: bool, + pub context_aliases: HashMap, } impl<'a> RootModuleConfig<'a> for KubernetesConfig<'a> { @@ -20,6 +22,7 @@ impl<'a> RootModuleConfig<'a> for KubernetesConfig<'a> { namespace: SegmentConfig::default(), style: Color::Cyan.bold(), disabled: true, + context_aliases: HashMap::new(), } } } diff --git a/src/modules/kubernetes.rs b/src/modules/kubernetes.rs index 018fd45a..e9ffd78e 100644 --- a/src/modules/kubernetes.rs +++ b/src/modules/kubernetes.rs @@ -68,7 +68,13 @@ pub fn module<'a>(context: &'a Context) -> Option> { module.get_prefix().set_value(KUBERNETES_PREFIX); module.create_segment("symbol", &config.symbol); - module.create_segment("context", &config.context.with_value(&kube_ctx)); + + let displayed_context = match config.context_aliases.get(&kube_ctx) { + None => &kube_ctx, + Some(&alias) => alias, + }; + + module.create_segment("context", &config.context.with_value(&displayed_context)); if kube_ns != "" { module.create_segment( "namespace",