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 <andytom@users.noreply.github.com>

Co-authored-by: Thomas O'Donnell <andytom@users.noreply.github.com>
This commit is contained in:
sk1985 2020-04-03 20:18:44 +02:00 committed by GitHub
parent dba3467dee
commit e38be5073f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 6 deletions

View File

@ -837,8 +837,9 @@ To enable it, set `disabled` to `false` in your configuration file.
### Options
| 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 |
@ -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

View File

@ -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<String, &'a str>,
}
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(),
}
}
}

View File

@ -68,7 +68,13 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
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",