diff --git a/README.md b/README.md index d8b484e..3fd6e7e 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ $ dockertags goodwithtech/dockle +---------+-------+----------------------+-------------+ # You can set limit, filter and format -$ dockertags -limit 2 -contain v0.2 -format json goodwithtech/dockle +$ dockertags -limit 2 -contain v -contain 2 -format json goodwithtech/dockle [ { "tags": [ diff --git a/cmd/dockertags/main.go b/cmd/dockertags/main.go index d206df2..6af1640 100644 --- a/cmd/dockertags/main.go +++ b/cmd/dockertags/main.go @@ -43,9 +43,9 @@ OPTIONS: Name: "limit, l", Usage: "set max tags count. if exist no tag image will be short numbers. limit=0 means fetch all tags", }, - cli.StringFlag{ + cli.StringSliceFlag{ Name: "contain, c", - Usage: "contains target string", + Usage: "contains target string. multiple string allows.", }, cli.StringFlag{ Name: "format, f", diff --git a/internal/types/types.go b/internal/types/types.go index b697e8c..52f166e 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -21,7 +21,7 @@ type RequestOption struct { // FilterOption : tag pattern type FilterOption struct { - Contain string + Contain []string } // ImageTag : tag information diff --git a/internal/utils/tag.go b/internal/utils/tag.go index 44b1728..18afa0e 100644 --- a/internal/utils/tag.go +++ b/internal/utils/tag.go @@ -8,11 +8,17 @@ import ( // MatchConditionTags retunrn matched option func MatchConditionTags(opt *types.FilterOption, tagNames []string) (contained bool) { - if opt.Contain == "" { + if len(opt.Contain) == 0 { return true } for _, tagName := range tagNames { - if strings.Contains(tagName, opt.Contain) { + var currentTagContained int + for _, target := range opt.Contain { + if strings.Contains(tagName, target) { + currentTagContained++ + } + } + if len(opt.Contain) == currentTagContained { return true } } diff --git a/pkg/provider/dockerhub/dockerhub.go b/pkg/provider/dockerhub/dockerhub.go index 36e03c9..b6837e8 100644 --- a/pkg/provider/dockerhub/dockerhub.go +++ b/pkg/provider/dockerhub/dockerhub.go @@ -114,7 +114,7 @@ func getTagResponse(ctx context.Context, auth dockertypes.AuthConfig, timeout ti func calcMaxRequestPage(totalCnt, needCnt int, option *types.FilterOption) int { maxPage := totalCnt/types.ImagePerPage + 1 - if needCnt == 0 || option.Contain != "" { + if needCnt == 0 || len(option.Contain) != 0 { return maxPage } needPage := needCnt/types.ImagePerPage + 1 diff --git a/pkg/run.go b/pkg/run.go index 29e03d0..1f20ffe 100644 --- a/pkg/run.go +++ b/pkg/run.go @@ -81,7 +81,7 @@ func genRequestOpt(c *cli.Context) types.RequestOption { func genFilterOpt(c *cli.Context) types.FilterOption { return types.FilterOption{ - Contain: c.String("contain"), + Contain: c.StringSlice("contain"), } }