From 0700dfa5945231997b49dd4779075d05a146cfdb Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Mon, 2 Sep 2024 12:01:36 +0200 Subject: [PATCH] feat(cftarget): allow files override resolves #5526 --- src/properties/map.go | 2 ++ src/segments/cf_target.go | 13 ++++++++---- website/docs/segments/cloud/cftarget.mdx | 27 +++++++++++++----------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/properties/map.go b/src/properties/map.go index 07632c7a..58b1dc51 100644 --- a/src/properties/map.go +++ b/src/properties/map.go @@ -53,6 +53,8 @@ const ( DefaultCacheTimeout = 10 // CacheTimeout cache timeout CacheTimeout Property = "cache_timeout" + // Files to trigger the segment on + Files Property = "files" ) type Map map[Property]any diff --git a/src/segments/cf_target.go b/src/segments/cf_target.go index 32bb942b..adb695a2 100644 --- a/src/segments/cf_target.go +++ b/src/segments/cf_target.go @@ -41,12 +41,17 @@ func (c *CfTarget) Enabled() bool { return c.setCFTargetStatus() } - manifest, err := c.env.HasParentFilePath("manifest.yml", false) - if err != nil || manifest.IsDir { - return false + files := c.props.GetStringArray(properties.Files, []string{"manifest.yml"}) + for _, file := range files { + manifest, err := c.env.HasParentFilePath(file, false) + if err != nil || manifest.IsDir { + continue + } + + return c.setCFTargetStatus() } - return c.setCFTargetStatus() + return false } func (c *CfTarget) setCFTargetStatus() bool { diff --git a/website/docs/segments/cloud/cftarget.mdx b/website/docs/segments/cloud/cftarget.mdx index 58da8934..faa11c5f 100644 --- a/website/docs/segments/cloud/cftarget.mdx +++ b/website/docs/segments/cloud/cftarget.mdx @@ -10,22 +10,25 @@ Display the details of the logged [Cloud Foundry endpoint][cf-target] (`cf targe ## Sample Configuration -import Config from '@site/src/components/Config.js'; +import Config from "@site/src/components/Config.js"; - + ## Properties -| Name | Type | Default | Description | -| -------------- | :------: | :------: | ------------------------------------------------------------------------------------------------------------------------------------------------- | -| `display_mode` | `string` | `always` |
  • `always`: the segment is always displayed
  • `files`: the segment is only displayed when a `manifest.yml` file is present
| +| Name | Type | Default | Description | +| -------------- | :--------: | :----------------: | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `display_mode` | `string` | `always` |
  • `always`: the segment is always displayed
  • `files`: the segment is only displayed when a `manifest.yml` file is present (or defined otherwise using `files`)
| +| `files` | `[]string` | `["manifest.yml"]` | on which files to display the segment on. Will look in parent folders as well | ## Template ([info][templates])