Skip to content

Commit

Permalink
improve: make os/arch filter list empty if parameter is an empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
hhyasdf committed Jul 5, 2023
1 parent baea159 commit 288dfb5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
goversion: 1.20
goversion: 1.20.4
extra_files: LICENSE README.md
8 changes: 5 additions & 3 deletions cmd/image-syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"os"

"github.com/AliyunContainerService/image-syncer/pkg/utils"

"github.com/AliyunContainerService/image-syncer/pkg/client"
"github.com/spf13/cobra"
)
Expand All @@ -27,7 +29,7 @@ var RootCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
// work starts here
client, err := client.NewSyncClient(configFile, authFile, imageFile, logPath, procNum, retries,
defaultRegistry, defaultNamespace, osFilterList, archFilterList)
defaultRegistry, defaultNamespace, utils.RemoveEmptyItems(osFilterList), utils.RemoveEmptyItems(archFilterList))
if err != nil {
return fmt.Errorf("init sync client error: %v", err)
}
Expand All @@ -48,8 +50,8 @@ func init() {
"default destination namespace when destination namespace is not given in the config file, can also be set with DEFAULT_NAMESPACE environment value")
RootCmd.PersistentFlags().IntVarP(&procNum, "proc", "p", 5, "numbers of working goroutines")
RootCmd.PersistentFlags().IntVarP(&retries, "retries", "r", 2, "times to retry failed task")
RootCmd.PersistentFlags().StringArrayVar(&osFilterList, "os", []string{}, "os list to filter source tags, not works for docker v2 schema1 media")
RootCmd.PersistentFlags().StringArrayVar(&archFilterList, "arch", []string{}, "architecture list to filter source tags")
RootCmd.PersistentFlags().StringArrayVar(&osFilterList, "os", []string{}, "os list to filter source tags, not works for docker v2 schema1 and OCI media")
RootCmd.PersistentFlags().StringArrayVar(&archFilterList, "arch", []string{}, "architecture list to filter source tags, not works for OCI media")
}

// Execute executes the RootCmd
Expand Down
11 changes: 11 additions & 0 deletions pkg/utils/slice.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package utils

func RemoveEmptyItems(slice []string) []string {
var result []string
for _, item := range slice {
if item != "" {
result = append(result, item)
}
}
return result
}

0 comments on commit 288dfb5

Please sign in to comment.