Add a platform.ParseAll helper
Signed-off-by: Jin Dong <djdongjin95@gmail.com>
This commit is contained in:
		@@ -24,7 +24,6 @@ import (
 | 
			
		||||
	"github.com/containerd/containerd/images/converter"
 | 
			
		||||
	"github.com/containerd/containerd/images/converter/uncompress"
 | 
			
		||||
	"github.com/containerd/containerd/platforms"
 | 
			
		||||
	ocispec "github.com/opencontainers/image-spec/specs-go/v1"
 | 
			
		||||
	"github.com/urfave/cli"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@@ -70,13 +69,9 @@ When '--all-platforms' is given all images in a manifest list must be available.
 | 
			
		||||
 | 
			
		||||
		if !context.Bool("all-platforms") {
 | 
			
		||||
			if pss := context.StringSlice("platform"); len(pss) > 0 {
 | 
			
		||||
				var all []ocispec.Platform
 | 
			
		||||
				for _, ps := range pss {
 | 
			
		||||
					p, err := platforms.Parse(ps)
 | 
			
		||||
					if err != nil {
 | 
			
		||||
						return fmt.Errorf("invalid platform %q: %w", ps, err)
 | 
			
		||||
					}
 | 
			
		||||
					all = append(all, p)
 | 
			
		||||
				all, err := platforms.ParseAll(pss)
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					return err
 | 
			
		||||
				}
 | 
			
		||||
				convertOpts = append(convertOpts, converter.WithPlatform(platforms.Ordered(all...)))
 | 
			
		||||
			} else {
 | 
			
		||||
 
 | 
			
		||||
@@ -22,7 +22,6 @@ import (
 | 
			
		||||
	"io"
 | 
			
		||||
	"os"
 | 
			
		||||
 | 
			
		||||
	ocispec "github.com/opencontainers/image-spec/specs-go/v1"
 | 
			
		||||
	"github.com/urfave/cli"
 | 
			
		||||
 | 
			
		||||
	"github.com/containerd/containerd/cmd/ctr/commands"
 | 
			
		||||
@@ -133,13 +132,9 @@ When '--all-platforms' is given all images in a manifest list must be available.
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if pss := context.StringSlice("platform"); len(pss) > 0 {
 | 
			
		||||
			var all []ocispec.Platform
 | 
			
		||||
			for _, ps := range pss {
 | 
			
		||||
				p, err := platforms.Parse(ps)
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					return fmt.Errorf("invalid platform %q: %w", ps, err)
 | 
			
		||||
				}
 | 
			
		||||
				all = append(all, p)
 | 
			
		||||
			all, err := platforms.ParseAll(pss)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return err
 | 
			
		||||
			}
 | 
			
		||||
			exportOpts = append(exportOpts, archive.WithPlatform(platforms.Ordered(all...)))
 | 
			
		||||
		} else {
 | 
			
		||||
 
 | 
			
		||||
@@ -101,13 +101,9 @@ command. As part of this process, we do the following:
 | 
			
		||||
 | 
			
		||||
			var sopts []image.StoreOpt
 | 
			
		||||
			if !context.Bool("all-platforms") {
 | 
			
		||||
				var p []ocispec.Platform
 | 
			
		||||
				for _, s := range context.StringSlice("platform") {
 | 
			
		||||
					ps, err := platforms.Parse(s)
 | 
			
		||||
					if err != nil {
 | 
			
		||||
						return fmt.Errorf("unable to parse platform %s: %w", s, err)
 | 
			
		||||
					}
 | 
			
		||||
					p = append(p, ps)
 | 
			
		||||
				p, err := platforms.ParseAll(context.StringSlice("platform"))
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					return err
 | 
			
		||||
				}
 | 
			
		||||
				if len(p) == 0 {
 | 
			
		||||
					p = append(p, platforms.DefaultSpec())
 | 
			
		||||
@@ -168,12 +164,9 @@ command. As part of this process, we do the following:
 | 
			
		||||
				return fmt.Errorf("unable to resolve image platforms: %w", err)
 | 
			
		||||
			}
 | 
			
		||||
		} else {
 | 
			
		||||
			for _, s := range context.StringSlice("platform") {
 | 
			
		||||
				ps, err := platforms.Parse(s)
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					return fmt.Errorf("unable to parse platform %s: %w", s, err)
 | 
			
		||||
				}
 | 
			
		||||
				p = append(p, ps)
 | 
			
		||||
			p, err = platforms.ParseAll(context.StringSlice("platform"))
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return err
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		if len(p) == 0 {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user