perf(pulumi): allow disabling upwards discovery (#4159)
* perf(pulumi): disable upwards discovery by default * change `search_upwards` default to `true`
This commit is contained in:
parent
aae1ed04ba
commit
af15de93c4
|
@ -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"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue