Add a platform.ParseAll helper

Signed-off-by: Jin Dong <djdongjin95@gmail.com>
This commit is contained in:
Jin Dong
2023-06-26 20:34:37 +00:00
parent b6abda73b8
commit 0a92661e69
7 changed files with 35 additions and 64 deletions

View File

@@ -158,6 +158,19 @@ func (m *matcher) String() string {
return Format(m.Platform)
}
// ParseAll parses a list of platform specifiers into a list of platform.
func ParseAll(specifiers []string) ([]specs.Platform, error) {
platforms := make([]specs.Platform, len(specifiers))
for i, s := range specifiers {
p, err := Parse(s)
if err != nil {
return nil, fmt.Errorf("invalid platform %s: %w", s, err)
}
platforms[i] = p
}
return platforms, nil
}
// Parse parses the platform specifier syntax into a platform declaration.
//
// Platform specifiers are in the format `<os>|<arch>|<os>/<arch>[/<variant>]`.