Skip to content

Commit

Permalink
check if have all and other platforms set in the --platform flag
Browse files Browse the repository at this point in the history
Signed-off-by: cpanato <ctadeu@gmail.com>
  • Loading branch information
cpanato committed Jun 6, 2022
1 parent e4a01f6 commit cb19b4c
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions pkg/commands/options/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package options

import (
"errors"
"log"
"strings"
)
Expand All @@ -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)
Expand All @@ -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
}

0 comments on commit cb19b4c

Please sign in to comment.