cli/command: use strings.Cut

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-12-27 16:29:21 +01:00
parent acc45f5494
commit cb19bf9f7d
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
1 changed files with 7 additions and 7 deletions

View File

@ -96,26 +96,26 @@ func PruneFilters(dockerCli Cli, pruneFilters filters.Args) filters.Args {
return pruneFilters return pruneFilters
} }
for _, f := range dockerCli.ConfigFile().PruneFilters { for _, f := range dockerCli.ConfigFile().PruneFilters {
parts := strings.SplitN(f, "=", 2) k, v, ok := strings.Cut(f, "=")
if len(parts) != 2 { if !ok {
continue continue
} }
if parts[0] == "label" { if k == "label" {
// CLI label filter supersede config.json. // CLI label filter supersede config.json.
// If CLI label filter conflict with config.json, // If CLI label filter conflict with config.json,
// skip adding label! filter in config.json. // skip adding label! filter in config.json.
if pruneFilters.Contains("label!") && pruneFilters.ExactMatch("label!", parts[1]) { if pruneFilters.Contains("label!") && pruneFilters.ExactMatch("label!", v) {
continue continue
} }
} else if parts[0] == "label!" { } else if k == "label!" {
// CLI label! filter supersede config.json. // CLI label! filter supersede config.json.
// If CLI label! filter conflict with config.json, // If CLI label! filter conflict with config.json,
// skip adding label filter in config.json. // skip adding label filter in config.json.
if pruneFilters.Contains("label") && pruneFilters.ExactMatch("label", parts[1]) { if pruneFilters.Contains("label") && pruneFilters.ExactMatch("label", v) {
continue continue
} }
} }
pruneFilters.Add(parts[0], parts[1]) pruneFilters.Add(k, v)
} }
return pruneFilters return pruneFilters