Skip to content

Commit af15de9

Browse files
authored
perf(pulumi): allow disabling upwards discovery (starship#4159)
* perf(pulumi): disable upwards discovery by default * change `search_upwards` default to `true`
1 parent aae1ed0 commit af15de9

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

.github/config-schema.json

+5
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,7 @@
10261026
"default": {
10271027
"disabled": false,
10281028
"format": "via [$symbol($username@)$stack]($style) ",
1029+
"search_upwards": true,
10291030
"style": "bold 5",
10301031
"symbol": "",
10311032
"version_format": "v${raw}"
@@ -3831,6 +3832,10 @@
38313832
"disabled": {
38323833
"default": false,
38333834
"type": "boolean"
3835+
},
3836+
"search_upwards": {
3837+
"default": true,
3838+
"type": "boolean"
38343839
}
38353840
}
38363841
},

docs/config/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -2700,7 +2700,7 @@ If you still want to enable it, [follow the example shown below](#with-pulumi-ve
27002700
By default the module will be shown if any of the following conditions are met:
27012701

27022702
- The current directory contains either `Pulumi.yaml` or `Pulumi.yml`
2703-
- A parent directory contains either `Pulumi.yaml` or `Pulumi.yml`
2703+
- A parent directory contains either `Pulumi.yaml` or `Pulumi.yml` unless `search_upwards` is set to `false`
27042704

27052705
### Options
27062706

@@ -2710,6 +2710,7 @@ By default the module will be shown if any of the following conditions are met:
27102710
| `version_format` | `"v${raw}"` | The version format. Available vars are `raw`, `major`, `minor`, & `patch` |
27112711
| `symbol` | `" "` | A format string shown before the Pulumi stack. |
27122712
| `style` | `"bold 5"` | The style for the module. |
2713+
| `search_upwards` | `true` | Enable discovery of pulumi config files in parent directories. |
27132714
| `disabled` | `false` | Disables the `pulumi` module. |
27142715

27152716
### Variables

src/configs/pulumi.rs

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub struct PulumiConfig<'a> {
99
pub symbol: &'a str,
1010
pub style: &'a str,
1111
pub disabled: bool,
12+
pub search_upwards: bool,
1213
}
1314

1415
impl<'a> Default for PulumiConfig<'a> {
@@ -19,6 +20,7 @@ impl<'a> Default for PulumiConfig<'a> {
1920
symbol: " ",
2021
style: "bold 5",
2122
disabled: false,
23+
search_upwards: true,
2224
}
2325
}
2426
}

src/modules/pulumi.rs

+52
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
3131
let mut module = context.new_module("pulumi");
3232
let config = PulumiConfig::try_load(module.config);
3333

34+
let project_file_in_cwd = context
35+
.try_begin_scan()?
36+
.set_files(&["Pulumi.yaml", "Pulumi.yml"])
37+
.is_match();
38+
39+
if !project_file_in_cwd && !config.search_upwards {
40+
return None;
41+
}
42+
3443
let project_file = find_package_file(&context.logical_dir)?;
3544

3645
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
@@ -409,4 +418,47 @@ mod tests {
409418
dir.close()?;
410419
Ok(())
411420
}
421+
422+
#[test]
423+
fn do_not_search_upwards() -> io::Result<()> {
424+
let dir = tempfile::tempdir()?;
425+
let child_dir = dir.path().join("child");
426+
std::fs::create_dir(&child_dir)?;
427+
let yaml = File::create(dir.path().join("Pulumi.yaml"))?;
428+
yaml.sync_all()?;
429+
430+
let actual = ModuleRenderer::new("pulumi")
431+
.path(&child_dir)
432+
.logical_path(&child_dir)
433+
.config(toml::toml! {
434+
[pulumi]
435+
format = "in [$symbol($stack)]($style) "
436+
search_upwards = false
437+
})
438+
.collect();
439+
let expected = None;
440+
assert_eq!(expected, actual);
441+
dir.close()
442+
}
443+
444+
#[test]
445+
fn search_upwards_default() -> io::Result<()> {
446+
let dir = tempfile::tempdir()?;
447+
let child_dir = dir.path().join("child");
448+
std::fs::create_dir(&child_dir)?;
449+
let yaml = File::create(dir.path().join("Pulumi.yaml"))?;
450+
yaml.sync_all()?;
451+
452+
let actual = ModuleRenderer::new("pulumi")
453+
.path(&child_dir)
454+
.logical_path(&child_dir)
455+
.config(toml::toml! {
456+
[pulumi]
457+
format = "in [$symbol($stack)]($style) "
458+
})
459+
.collect();
460+
let expected = Some(format!("in {} ", Color::Fixed(5).bold().paint(" ")));
461+
assert_eq!(expected, actual);
462+
dir.close()
463+
}
412464
}

0 commit comments

Comments
 (0)