Skip to content

Commit

Permalink
allow multiple contain string (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomoyamachi authored Dec 25, 2019
1 parent d4d3d7e commit 348dddf
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
4 changes: 2 additions & 2 deletions cmd/dockertags/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion internal/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type RequestOption struct {

// FilterOption : tag pattern
type FilterOption struct {
Contain string
Contain []string
}

// ImageTag : tag information
Expand Down
10 changes: 8 additions & 2 deletions internal/utils/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/dockerhub/dockerhub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
}

Expand Down

0 comments on commit 348dddf

Please sign in to comment.