From 288dfb58bb248fb99f273d2170594b8471dca73d Mon Sep 17 00:00:00 2001 From: hhyasdf <552483776@qq.com> Date: Wed, 5 Jul 2023 11:10:00 +0800 Subject: [PATCH] improve: make os/arch filter list empty if parameter is an empty string --- .github/workflows/release.yml | 2 +- cmd/image-syncer.go | 8 +++++--- pkg/utils/slice.go | 11 +++++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 pkg/utils/slice.go diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8d6317d..85166e9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 diff --git a/cmd/image-syncer.go b/cmd/image-syncer.go index ee87cbb..029a797 100644 --- a/cmd/image-syncer.go +++ b/cmd/image-syncer.go @@ -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" ) @@ -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) } @@ -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 diff --git a/pkg/utils/slice.go b/pkg/utils/slice.go new file mode 100644 index 0000000..b6e7287 --- /dev/null +++ b/pkg/utils/slice.go @@ -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 +}