mirror of
https://github.com/starship/starship.git
synced 2026-06-23 02:05:51 +07:00
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:
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user