Merge pull request #2548 from ijc/platforms-must-parse
platforms: Add `MustParse`
This commit is contained in:
commit
a69a0b0192
@ -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 == "" {
|
||||||
|
Loading…
Reference in New Issue
Block a user