diff options
author | Shu Kutsuzawa <cappyzawa@yahoo.ne.jp> | 2021-02-18 02:57:40 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-17 18:57:40 +0100 |
commit | 82c7fd6742add35a795d43977ee6f5bb3e28ea69 (patch) | |
tree | 9ba06ecdce604128556c0fa2b9ab30d4824b2144 | |
parent | 96b36322e55cf92cf0ce09d319c72aad946cd550 (diff) |
feat(terraform): Configure when the module is shown (#2324)
This makes it possible to configure when the terraform module is shown
based on the contents of a directory. This should make it possible to
be a lot more granular when configuring the module.
-rw-r--r-- | docs/config/README.md | 17 | ||||
-rw-r--r-- | src/configs/terraform.rs | 6 | ||||
-rw-r--r-- | src/modules/terraform.rs | 15 |
3 files changed, 22 insertions, 16 deletions
diff --git a/docs/config/README.md b/docs/config/README.md index 20b43cc71..73d3b4cdb 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -2386,19 +2386,22 @@ If you still want to enable it, [follow the example shown below](#with-version). ::: -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 `.terraform` folder - Current directory contains a file with the `.tf` or `.hcl` extensions ### Options -| Option | Default | Description | -| ---------- | ------------------------------------ | ----------------------------------------------------- | -| `format` | `"via [$symbol$workspace]($style) "` | The format string for the module. | -| `symbol` | `"💠"` | A format string shown before the terraform workspace. | -| `style` | `"bold 105"` | The style for the module. | -| `disabled` | `false` | Disables the `terraform` module. | +| Option | Default | Description | +| ------------------- | ------------------------------------ | ----------------------------------------------------- | +| `format` | `"via [$symbol$workspace]($style) "` | The format string for the module. | +| `symbol` | `"💠"` | A format string shown before the terraform workspace. | +| `detect_extensions` | `["tf", "hcl"]` | Which extensions should trigger this module. | +| `detect_files` | `[]` | Which filenames should trigger this module. | +| `detect_folders` | `[".terraform"]` | Which folders should trigger this module. | +| `style` | `"bold 105"` | The style for the module. | +| `disabled` | `false` | Disables the `terraform` module. | ### Variables diff --git a/src/configs/terraform.rs b/src/configs/terraform.rs index 950b2b004..132cc4238 100644 --- a/src/configs/terraform.rs +++ b/src/configs/terraform.rs @@ -8,6 +8,9 @@ pub struct TerraformConfig<'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 TerraformConfig<'a> { @@ -17,6 +20,9 @@ impl<'a> RootModuleConfig<'a> for TerraformConfig<'a> { symbol: "💠", style: "bold 105", disabled: false, + detect_extensions: vec!["tf", "hcl"], + detect_files: vec![], + detect_folders: vec![".terraform"], } } } diff --git a/src/modules/terraform.rs b/src/modules/terraform.rs index f3cf168a5..c051abb99 100644 --- a/src/modules/terraform.rs +++ b/src/modules/terraform.rs @@ -8,24 +8,21 @@ use std::io; use std::path::PathBuf; /// Creates a module with the current Terraform version and workspace -/// -/// Will display the Terraform version and workspace if any of the following criteria are met: -/// - Current directory contains a `.terraform` directory -/// - Current directory contains a file with the `.tf` extension pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { + let mut module = context.new_module("terraform"); + let config: TerraformConfig = TerraformConfig::try_load(module.config); + let is_terraform_project = context .try_begin_scan()? - .set_folders(&[".terraform"]) - .set_extensions(&["tf", "hcl"]) + .set_files(&config.detect_files) + .set_folders(&config.detect_folders) + .set_extensions(&config.detect_extensions) .is_match(); if !is_terraform_project { return None; } - let mut module = context.new_module("terraform"); - let config: TerraformConfig = TerraformConfig::try_load(module.config); - let parsed = StringFormatter::new(config.format).and_then(|formatter| { formatter .map_meta(|variable, _| match variable { |