1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-06-12 21:32:21 +00:00
starship/src/configs/kubernetes.rs

58 lines
1.6 KiB
Rust
Raw Normal View History

use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(
feature = "config-schema",
derive(schemars::JsonSchema),
schemars(deny_unknown_fields)
)]
#[serde(default)]
pub struct KubernetesConfig<'a> {
pub symbol: &'a str,
pub format: &'a str,
pub style: &'a str,
pub disabled: bool,
pub context_aliases: HashMap<String, &'a str>,
pub user_aliases: HashMap<String, &'a str>,
pub detect_extensions: Vec<&'a str>,
pub detect_files: Vec<&'a str>,
pub detect_folders: Vec<&'a str>,
pub detect_env_vars: Vec<&'a str>,
feat(kubernetes): Add styling based on current context (#4550) * feat(kubernetes): Add styling based on current context Add an ability to customize the configuration of the kubernetes module style, based on the current context. A new variable is added to the config section, called environments, which is a list of possible customizations. Each such customization is an object with a context_pattern regex, which matches context name, and an optional style and icon that will override the global configuration, if the currently used context matched the context_pattern. Based on multiple attempts to add per-context styling and symbols to the kubernetes module. - https://github.com/starship/starship/pull/1568 by @lht https://github.com/lht -> base - https://github.com/starship/starship/pull/614 by @nomaed https://github.com/nomaed -> naming, symbol, some tests Rebased and combined by @jankatins Contains the following squasched commits - Rename to contexts and move aliases into contexts - Move deprecated functions to a submodule - Cleanup: ignore None-valued KubeCtxComponents - Add regex func + clean up matching-context search - Placate paper clip Closes: https://github.com/starship/starship/issues/570 Co-authored-by: =?UTF-8?q?Boris=20Aranovic=CC=8C?= <nomaed@gmail.com> Co-authored-by: Jan Katins <jasc@gmx.net> Co-authored-by: Kevin Song <chips@ksong.dev> * refactor(kubernetes): Remove options and use clearer names * test(kubernetes): Handle duplicated contexts right * refactor(kubernetes): Cleaner user matching * fix(kubernetes): Only show warning in case of problems * feat(kubernetes): Add back alias replacements * refactor(kubernetes): Cleanup rust usage --------- Co-authored-by: Haitao Li <lihaitao@gmail.com> Co-authored-by: =?UTF-8?q?Boris=20Aranovic=CC=8C?= <nomaed@gmail.com> Co-authored-by: Kevin Song <chips@ksong.dev> Co-authored-by: David Knaack <davidkna@users.noreply.github.com>
2023-09-02 07:19:33 +00:00
pub contexts: Vec<KubernetesContextConfig<'a>>,
}
impl<'a> Default for KubernetesConfig<'a> {
fn default() -> Self {
KubernetesConfig {
symbol: "",
format: "[$symbol$context( \\($namespace\\))]($style) in ",
style: "cyan bold",
disabled: true,
context_aliases: HashMap::new(),
user_aliases: HashMap::new(),
detect_extensions: vec![],
detect_files: vec![],
detect_folders: vec![],
detect_env_vars: vec![],
feat(kubernetes): Add styling based on current context (#4550) * feat(kubernetes): Add styling based on current context Add an ability to customize the configuration of the kubernetes module style, based on the current context. A new variable is added to the config section, called environments, which is a list of possible customizations. Each such customization is an object with a context_pattern regex, which matches context name, and an optional style and icon that will override the global configuration, if the currently used context matched the context_pattern. Based on multiple attempts to add per-context styling and symbols to the kubernetes module. - https://github.com/starship/starship/pull/1568 by @lht https://github.com/lht -> base - https://github.com/starship/starship/pull/614 by @nomaed https://github.com/nomaed -> naming, symbol, some tests Rebased and combined by @jankatins Contains the following squasched commits - Rename to contexts and move aliases into contexts - Move deprecated functions to a submodule - Cleanup: ignore None-valued KubeCtxComponents - Add regex func + clean up matching-context search - Placate paper clip Closes: https://github.com/starship/starship/issues/570 Co-authored-by: =?UTF-8?q?Boris=20Aranovic=CC=8C?= <nomaed@gmail.com> Co-authored-by: Jan Katins <jasc@gmx.net> Co-authored-by: Kevin Song <chips@ksong.dev> * refactor(kubernetes): Remove options and use clearer names * test(kubernetes): Handle duplicated contexts right * refactor(kubernetes): Cleaner user matching * fix(kubernetes): Only show warning in case of problems * feat(kubernetes): Add back alias replacements * refactor(kubernetes): Cleanup rust usage --------- Co-authored-by: Haitao Li <lihaitao@gmail.com> Co-authored-by: =?UTF-8?q?Boris=20Aranovic=CC=8C?= <nomaed@gmail.com> Co-authored-by: Kevin Song <chips@ksong.dev> Co-authored-by: David Knaack <davidkna@users.noreply.github.com>
2023-09-02 07:19:33 +00:00
contexts: vec![],
}
}
}
feat(kubernetes): Add styling based on current context (#4550) * feat(kubernetes): Add styling based on current context Add an ability to customize the configuration of the kubernetes module style, based on the current context. A new variable is added to the config section, called environments, which is a list of possible customizations. Each such customization is an object with a context_pattern regex, which matches context name, and an optional style and icon that will override the global configuration, if the currently used context matched the context_pattern. Based on multiple attempts to add per-context styling and symbols to the kubernetes module. - https://github.com/starship/starship/pull/1568 by @lht https://github.com/lht -> base - https://github.com/starship/starship/pull/614 by @nomaed https://github.com/nomaed -> naming, symbol, some tests Rebased and combined by @jankatins Contains the following squasched commits - Rename to contexts and move aliases into contexts - Move deprecated functions to a submodule - Cleanup: ignore None-valued KubeCtxComponents - Add regex func + clean up matching-context search - Placate paper clip Closes: https://github.com/starship/starship/issues/570 Co-authored-by: =?UTF-8?q?Boris=20Aranovic=CC=8C?= <nomaed@gmail.com> Co-authored-by: Jan Katins <jasc@gmx.net> Co-authored-by: Kevin Song <chips@ksong.dev> * refactor(kubernetes): Remove options and use clearer names * test(kubernetes): Handle duplicated contexts right * refactor(kubernetes): Cleaner user matching * fix(kubernetes): Only show warning in case of problems * feat(kubernetes): Add back alias replacements * refactor(kubernetes): Cleanup rust usage --------- Co-authored-by: Haitao Li <lihaitao@gmail.com> Co-authored-by: =?UTF-8?q?Boris=20Aranovic=CC=8C?= <nomaed@gmail.com> Co-authored-by: Kevin Song <chips@ksong.dev> Co-authored-by: David Knaack <davidkna@users.noreply.github.com>
2023-09-02 07:19:33 +00:00
#[derive(Clone, Deserialize, Serialize, Default)]
#[cfg_attr(
feature = "config-schema",
derive(schemars::JsonSchema),
schemars(deny_unknown_fields)
)]
#[serde(default)]
pub struct KubernetesContextConfig<'a> {
pub context_pattern: &'a str,
pub user_pattern: Option<&'a str>,
pub symbol: Option<&'a str>,
pub style: Option<&'a str>,
pub context_alias: Option<&'a str>,
pub user_alias: Option<&'a str>,
}