Skip to content

Commit d242d40

Browse files
vladimyrcymruu
andauthored
feat(gcloud): honor CLOUDSDK_CORE_PROJECT env variable (starship#2596)
Co-authored-by: Filip Bachul <[email protected]>
1 parent 65cbd20 commit d242d40

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

src/modules/gcloud.rs

+38-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
128128
.unwrap_or(region)
129129
})
130130
.map(Ok),
131-
"project" => gcloud_context.get_project().map(Ok),
131+
"project" => context
132+
.get_env("CLOUDSDK_CORE_PROJECT")
133+
.or_else(|| gcloud_context.get_project())
134+
.map(Ok),
132135
"active" => Some(Ok(gcloud_context.config_name.to_owned())),
133136
_ => None,
134137
})
@@ -302,6 +305,40 @@ project = abc
302305
dir.close()
303306
}
304307

308+
#[test]
309+
fn project_set_in_env() -> io::Result<()> {
310+
let dir = tempfile::tempdir()?;
311+
let active_config_path = dir.path().join("active_config");
312+
let mut active_config_file = File::create(&active_config_path)?;
313+
active_config_file.write_all(b"default")?;
314+
315+
create_dir(dir.path().join("configurations"))?;
316+
let config_default_path = dir.path().join("configurations").join("config_default");
317+
let mut config_default_file = File::create(&config_default_path)?;
318+
config_default_file.write_all(
319+
b"\
320+
[core]
321+
project = abc
322+
",
323+
)?;
324+
325+
let actual = ModuleRenderer::new("gcloud")
326+
.env("CLOUDSDK_CORE_PROJECT", "env_project")
327+
.env("CLOUDSDK_CONFIG", dir.path().to_string_lossy())
328+
.config(toml::toml! {
329+
[gcloud]
330+
format = "on [$symbol$project]($style) "
331+
})
332+
.collect();
333+
let expected = Some(format!(
334+
"on {} ",
335+
Color::Blue.bold().paint("☁️ env_project")
336+
));
337+
338+
assert_eq!(actual, expected);
339+
dir.close()
340+
}
341+
305342
#[test]
306343
fn region_not_set_with_display_region() -> io::Result<()> {
307344
let dir = tempfile::tempdir()?;

0 commit comments

Comments
 (0)