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.
This commit is contained in:
Shu Kutsuzawa
2021-02-18 02:57:40 +09:00
committed by GitHub
parent 96b36322e5
commit 82c7fd6742
3 changed files with 22 additions and 16 deletions
+6
View File
@@ -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"],
}
}
}
+6 -9
View File
@@ -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 {