From cb19b4c5e4585a813d66515b0fbf71e298edd7b5 Mon Sep 17 00:00:00 2001 From: cpanato Date: Wed, 2 Mar 2022 14:13:08 +0100 Subject: [PATCH 1/2] check if have all and other platforms set in the --platform flag Signed-off-by: cpanato --- pkg/commands/options/validate.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pkg/commands/options/validate.go b/pkg/commands/options/validate.go index 4106bd6441..b2be56c0da 100644 --- a/pkg/commands/options/validate.go +++ b/pkg/commands/options/validate.go @@ -15,6 +15,7 @@ package options import ( + "errors" "log" "strings" ) @@ -39,6 +40,14 @@ The --local flag might be deprecated in the future. ----------------------------------------------------------------- ` +const platformsFlagWarning = `ERROR! +----------------------------------------------------------------------- +The --platform was set with all and other specific platforms. + +Please choose either all or a specific one, ie. --platform=linux/arm64 +----------------------------------------------------------------------- +` + func Validate(po *PublishOptions, bo *BuildOptions) error { if po.Bare && po.BaseImportPaths { log.Print(bareBaseFlagsWarning) @@ -49,5 +58,20 @@ func Validate(po *PublishOptions, bo *BuildOptions) error { log.Print(localFlagsWarning) } + if len(bo.Platforms) > 1 { + hasAll := false + + for _, platform := range bo.Platforms { + if platform == "all" { + hasAll = true + } + } + + if hasAll { + log.Print(platformsFlagWarning) + return errors.New("all or specific platforms should be used") + } + } + return nil } From 57b55f203ea331907c0cd8c23c93d3dc1e2f9f0c Mon Sep 17 00:00:00 2001 From: cpanato Date: Fri, 4 Mar 2022 10:16:54 +0100 Subject: [PATCH 2/2] update per feedback Signed-off-by: cpanato --- pkg/commands/options/validate.go | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/pkg/commands/options/validate.go b/pkg/commands/options/validate.go index b2be56c0da..142e16b79c 100644 --- a/pkg/commands/options/validate.go +++ b/pkg/commands/options/validate.go @@ -40,14 +40,6 @@ The --local flag might be deprecated in the future. ----------------------------------------------------------------- ` -const platformsFlagWarning = `ERROR! ------------------------------------------------------------------------ -The --platform was set with all and other specific platforms. - -Please choose either all or a specific one, ie. --platform=linux/arm64 ------------------------------------------------------------------------ -` - func Validate(po *PublishOptions, bo *BuildOptions) error { if po.Bare && po.BaseImportPaths { log.Print(bareBaseFlagsWarning) @@ -59,18 +51,11 @@ func Validate(po *PublishOptions, bo *BuildOptions) error { } if len(bo.Platforms) > 1 { - hasAll := false - for _, platform := range bo.Platforms { if platform == "all" { - hasAll = true + return errors.New("all or specific platforms should be used") } } - - if hasAll { - log.Print(platformsFlagWarning) - return errors.New("all or specific platforms should be used") - } } return nil