fix: parse the subsys env error (#18319)

This commit is contained in:
jiuker 2023-10-26 23:12:57 +08:00 committed by GitHub
parent 54aed421b8
commit dbc2368a7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1091,6 +1091,8 @@ func (c Config) GetAvailableTargets(subSys string) ([]string, error) {
seen.Add(k) seen.Add(k)
} }
// env:prefix
filterMap := map[string]string{}
// Add targets that are configured via environment variables. // Add targets that are configured via environment variables.
for _, param := range defKVS { for _, param := range defKVS {
envVarPrefix := getEnvVarName(subSys, Default, param.Key) + Default envVarPrefix := getEnvVarName(subSys, Default, param.Key) + Default
@ -1098,11 +1100,21 @@ func (c Config) GetAvailableTargets(subSys string) ([]string, error) {
for _, k := range envsWithPrefix { for _, k := range envsWithPrefix {
tgtName := strings.TrimPrefix(k, envVarPrefix) tgtName := strings.TrimPrefix(k, envVarPrefix)
if tgtName != "" { if tgtName != "" {
seen.Add(tgtName) if v, ok := filterMap[k]; ok {
if strings.HasPrefix(envVarPrefix, v) {
filterMap[k] = envVarPrefix
}
} else {
filterMap[k] = envVarPrefix
}
} }
} }
} }
for k, v := range filterMap {
seen.Add(strings.TrimPrefix(k, v))
}
seen.Remove(Default) seen.Remove(Default)
targets := seen.ToSlice() targets := seen.ToSlice()
sort.Strings(targets) sort.Strings(targets)