diff options
author | David Knaack <davidkna@users.noreply.github.com> | 2022-07-10 11:14:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-10 11:14:43 +0200 |
commit | af15de93c4494bb08d8c2cb3dbf54951f6bc9239 (patch) | |
tree | 64f8e00cfb698b0865587d42f3dc780ac45f8009 | |
parent | aae1ed04babf4c7d8baaad670c076947d7200675 (diff) |
perf(pulumi): allow disabling upwards discovery (#4159)
* perf(pulumi): disable upwards discovery by default
* change `search_upwards` default to `true`
-rw-r--r-- | .github/config-schema.json | 5 | ||||
-rw-r--r-- | docs/config/README.md | 3 | ||||
-rw-r--r-- | src/configs/pulumi.rs | 2 | ||||
-rw-r--r-- | src/modules/pulumi.rs | 52 |
4 files changed, 61 insertions, 1 deletions
diff --git a/.github/config-schema.json b/.github/config-schema.json index 5631940b0..5a3247f77 100644 --- a/.github/config-schema.json +++ b/.github/config-schema.json @@ -1026,6 +1026,7 @@ "default": { "disabled": false, "format": "via [$symbol($username@)$stack]($style) ", + "search_upwards": true, "style": "bold 5", "symbol": " ", "version_format": "v${raw}" @@ -3831,6 +3832,10 @@ "disabled": { "default": false, "type": "boolean" + }, + "search_upwards": { + "default": true, + "type": "boolean" } } }, diff --git a/docs/config/README.md b/docs/config/README.md index 77c1927c6..e83478910 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -2700,7 +2700,7 @@ If you still want to enable it, [follow the example shown below](#with-pulumi-ve By default the module will be shown if any of the following conditions are met: - The current directory contains either `Pulumi.yaml` or `Pulumi.yml` -- A parent directory contains either `Pulumi.yaml` or `Pulumi.yml` +- A parent directory contains either `Pulumi.yaml` or `Pulumi.yml` unless `search_upwards` is set to `false` ### Options @@ -2710,6 +2710,7 @@ By default the module will be shown if any of the following conditions are met: | `version_format` | `"v${raw}"` | The version format. Available vars are `raw`, `major`, `minor`, & `patch` | | `symbol` | `" "` | A format string shown before the Pulumi stack. | | `style` | `"bold 5"` | The style for the module. | +| `search_upwards` | `true` | Enable discovery of pulumi config files in parent directories. | | `disabled` | `false` | Disables the `pulumi` module. | ### Variables diff --git a/src/configs/pulumi.rs b/src/configs/pulumi.rs index d372c900e..043cdab02 100644 --- a/src/configs/pulumi.rs +++ b/src/configs/pulumi.rs @@ -9,6 +9,7 @@ pub struct PulumiConfig<'a> { pub symbol: &'a str, pub style: &'a str, pub disabled: bool, + pub search_upwards: bool, } impl<'a> Default for PulumiConfig<'a> { @@ -19,6 +20,7 @@ impl<'a> Default for PulumiConfig<'a> { symbol: " ", style: "bold 5", disabled: false, + search_upwards: true, } } } diff --git a/src/modules/pulumi.rs b/src/modules/pulumi.rs index 63ef63520..5b2f975d4 100644 --- a/src/modules/pulumi.rs +++ b/src/modules/pulumi.rs @@ -31,6 +31,15 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { let mut module = context.new_module("pulumi"); let config = PulumiConfig::try_load(module.config); + let project_file_in_cwd = context + .try_begin_scan()? + .set_files(&["Pulumi.yaml", "Pulumi.yml"]) + .is_match(); + + if !project_file_in_cwd && !config.search_upwards { + return None; + } + let project_file = find_package_file(&context.logical_dir)?; let parsed = StringFormatter::new(config.format).and_then(|formatter| { @@ -409,4 +418,47 @@ mod tests { dir.close()?; Ok(()) } + + #[test] + fn do_not_search_upwards() -> io::Result<()> { + let dir = tempfile::tempdir()?; + let child_dir = dir.path().join("child"); + std::fs::create_dir(&child_dir)?; + let yaml = File::create(dir.path().join("Pulumi.yaml"))?; + yaml.sync_all()?; + + let actual = ModuleRenderer::new("pulumi") + .path(&child_dir) + .logical_path(&child_dir) + .config(toml::toml! { + [pulumi] + format = "in [$symbol($stack)]($style) " + search_upwards = false + }) + .collect(); + let expected = None; + assert_eq!(expected, actual); + dir.close() + } + + #[test] + fn search_upwards_default() -> io::Result<()> { + let dir = tempfile::tempdir()?; + let child_dir = dir.path().join("child"); + std::fs::create_dir(&child_dir)?; + let yaml = File::create(dir.path().join("Pulumi.yaml"))?; + yaml.sync_all()?; + + let actual = ModuleRenderer::new("pulumi") + .path(&child_dir) + .logical_path(&child_dir) + .config(toml::toml! { + [pulumi] + format = "in [$symbol($stack)]($style) " + }) + .collect(); + let expected = Some(format!("in {} ", Color::Fixed(5).bold().paint(" "))); + assert_eq!(expected, actual); + dir.close() + } } |