commands: add platforms dedupe

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi
2019-04-17 17:55:27 -07:00
parent e773d0eb2a
commit e40318e2cc
7 changed files with 117 additions and 14 deletions

View File

@ -30,3 +30,29 @@ func Parse(platformsStr []string) ([]specs.Platform, error) {
}
return out, nil
}
func Dedupe(in []specs.Platform) []specs.Platform {
m := map[string]struct{}{}
out := make([]specs.Platform, 0, len(in))
for _, p := range in {
p := platforms.Normalize(p)
key := platforms.Format(p)
if _, ok := m[key]; ok {
continue
}
m[key] = struct{}{}
out = append(out, p)
}
return out
}
func Format(in []specs.Platform) []string {
if len(in) == 0 {
return nil
}
out := make([]string, 0, len(in))
for _, p := range in {
out = append(out, platforms.Format(p))
}
return out
}