mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-16 01:57:07 +00:00
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:
parent
96b36322e5
commit
82c7fd6742
@ -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
|
- The current directory contains a `.terraform` folder
|
||||||
- Current directory contains a file with the `.tf` or `.hcl` extensions
|
- Current directory contains a file with the `.tf` or `.hcl` extensions
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
| Option | Default | Description |
|
| Option | Default | Description |
|
||||||
| ---------- | ------------------------------------ | ----------------------------------------------------- |
|
| ------------------- | ------------------------------------ | ----------------------------------------------------- |
|
||||||
| `format` | `"via [$symbol$workspace]($style) "` | The format string for the module. |
|
| `format` | `"via [$symbol$workspace]($style) "` | The format string for the module. |
|
||||||
| `symbol` | `"💠 "` | A format string shown before the terraform workspace. |
|
| `symbol` | `"💠"` | A format string shown before the terraform workspace. |
|
||||||
| `style` | `"bold 105"` | The style for the module. |
|
| `detect_extensions` | `["tf", "hcl"]` | Which extensions should trigger this module. |
|
||||||
| `disabled` | `false` | Disables the `terraform` 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
|
### Variables
|
||||||
|
|
||||||
|
@ -8,6 +8,9 @@ pub struct TerraformConfig<'a> {
|
|||||||
pub symbol: &'a str,
|
pub symbol: &'a str,
|
||||||
pub style: &'a str,
|
pub style: &'a str,
|
||||||
pub disabled: bool,
|
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> {
|
impl<'a> RootModuleConfig<'a> for TerraformConfig<'a> {
|
||||||
@ -17,6 +20,9 @@ impl<'a> RootModuleConfig<'a> for TerraformConfig<'a> {
|
|||||||
symbol: "💠 ",
|
symbol: "💠 ",
|
||||||
style: "bold 105",
|
style: "bold 105",
|
||||||
disabled: false,
|
disabled: false,
|
||||||
|
detect_extensions: vec!["tf", "hcl"],
|
||||||
|
detect_files: vec![],
|
||||||
|
detect_folders: vec![".terraform"],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,24 +8,21 @@ use std::io;
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
/// Creates a module with the current Terraform version and workspace
|
/// 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>> {
|
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
|
let is_terraform_project = context
|
||||||
.try_begin_scan()?
|
.try_begin_scan()?
|
||||||
.set_folders(&[".terraform"])
|
.set_files(&config.detect_files)
|
||||||
.set_extensions(&["tf", "hcl"])
|
.set_folders(&config.detect_folders)
|
||||||
|
.set_extensions(&config.detect_extensions)
|
||||||
.is_match();
|
.is_match();
|
||||||
|
|
||||||
if !is_terraform_project {
|
if !is_terraform_project {
|
||||||
return None;
|
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| {
|
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
|
||||||
formatter
|
formatter
|
||||||
.map_meta(|variable, _| match variable {
|
.map_meta(|variable, _| match variable {
|
||||||
|
Loading…
Reference in New Issue
Block a user