diff options
author | Thomas O'Donnell <andytom@users.noreply.github.com> | 2021-02-21 19:57:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-21 19:57:23 +0100 |
commit | 0083e28827043a9b51765b6556f3fb6a5995db95 (patch) | |
tree | e1a78923079333a83924228e90444107160e1e1d | |
parent | 64288c2e0437a570f0ff0e6f374f97967bb70ea0 (diff) |
feat(helm): Configure when the module is shown (#2352)
This makes it possible to configure when the helm module is shown based
on the contents of a directory.
-rw-r--r-- | docs/config/README.md | 17 | ||||
-rw-r--r-- | src/configs/helm.rs | 6 | ||||
-rw-r--r-- | src/modules/helm.rs | 13 |
3 files changed, 22 insertions, 14 deletions
diff --git a/docs/config/README.md b/docs/config/README.md index 400f7039d..784eea70f 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -1291,19 +1291,22 @@ format = "via [🏎💨 $version](bold cyan) " ## Helm The `helm` module shows the currently installed version of Helm. -The module will be shown if any of the following conditions are met: +By default the module will be shown if any of the following conditions are met: - The current directory contains a `helmfile.yaml` file - The current directory contains a `Chart.yaml` file ### Options -| Option | Default | Description | -| ---------- | ---------------------------------- | ------------------------------------------------ | -| `format` | `"via [$symbol($version )]($style)"` | The format for the module. | -| `symbol` | `"⎈ "` | A format string representing the symbol of Helm. | -| `style` | `"bold white"` | The style for the module. | -| `disabled` | `false` | Disables the `helm` module. | +| Option | Default | Description | +| ------------------- | ------------------------------------ | ------------------------------------------------ | +| `format` | `"via [$symbol($version )]($style)"` | The format for the module. | +| `detect_extensions` | `[]` | Which extensions should trigger this module. | +| `detect_files` | `["helmfile.yaml", "Chart.yaml"]` | Which filenames should trigger this module. | +| `detect_folders` | `[]` | Which folders should trigger this modules. | +| `symbol` | `"⎈ "` | A format string representing the symbol of Helm. | +| `style` | `"bold white"` | The style for the module. | +| `disabled` | `false` | Disables the `helm` module. | ### Variables diff --git a/src/configs/helm.rs b/src/configs/helm.rs index afcf651ae..60f31aa7b 100644 --- a/src/configs/helm.rs +++ b/src/configs/helm.rs @@ -8,6 +8,9 @@ pub struct HelmConfig<'a> { pub symbol: &'a str, pub style: &'a str, pub disabled: bool, + pub detect_extensions: Vec<&'a str>, + pub detect_files: Vec<&'a str>, + pub detect_folders: Vec<&'a str>, } impl<'a> RootModuleConfig<'a> for HelmConfig<'a> { @@ -17,6 +20,9 @@ impl<'a> RootModuleConfig<'a> for HelmConfig<'a> { symbol: "⎈ ", style: "bold white", disabled: false, + detect_extensions: vec![], + detect_files: vec!["helmfile.yaml", "Chart.yaml"], + detect_folders: vec![], } } } diff --git a/src/modules/helm.rs b/src/modules/helm.rs index 8e206a8df..1b1f77b64 100644 --- a/src/modules/helm.rs +++ b/src/modules/helm.rs @@ -4,22 +4,21 @@ use crate::configs::helm::HelmConfig; use crate::formatter::StringFormatter; /// Creates a module with the current Helm version -/// -/// Will display the Helm version if any of the following criteria are met: -/// - Current directory contains a `helmfile.yaml` file -/// - Current directory contains a `Chart.yaml` file pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { + let mut module = context.new_module("helm"); + let config = HelmConfig::try_load(module.config); + let is_helm_project = context .try_begin_scan()? - .set_files(&["helmfile.yaml", "Chart.yaml"]) + .set_files(&config.detect_files) + .set_extensions(&config.detect_extensions) + .set_folders(&config.detect_folders) .is_match(); if !is_helm_project { return None; } - let mut module = context.new_module("helm"); - let config = HelmConfig::try_load(module.config); let parsed = StringFormatter::new(config.format).and_then(|formatter| { formatter .map_meta(|var, _| match var { |