Merge pull request #2548 from ijc/platforms-must-parse

platforms: Add `MustParse`
This commit is contained in:
Phil Estes 2018-08-15 10:17:41 -04:00 committed by GitHub
commit a69a0b0192
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -109,6 +109,7 @@ package platforms
import ( import (
"regexp" "regexp"
"runtime" "runtime"
"strconv"
"strings" "strings"
"github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/errdefs"
@ -230,6 +231,16 @@ func Parse(specifier string) (specs.Platform, error) {
return specs.Platform{}, errors.Wrapf(errdefs.ErrInvalidArgument, "%q: cannot parse platform specifier", specifier) return specs.Platform{}, errors.Wrapf(errdefs.ErrInvalidArgument, "%q: cannot parse platform specifier", specifier)
} }
// MustParse is like Parses but panics if the specifier cannot be parsed.
// Simplifies initialization of global variables.
func MustParse(specifier string) specs.Platform {
p, err := Parse(specifier)
if err != nil {
panic("platform: Parse(" + strconv.Quote(specifier) + "): " + err.Error())
}
return p
}
// Format returns a string specifier from the provided platform specification. // Format returns a string specifier from the provided platform specification.
func Format(platform specs.Platform) string { func Format(platform specs.Platform) string {
if platform.OS == "" { if platform.OS == "" {