Skip to content

Commit

Permalink
Apply code review recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
burdiyan committed Sep 10, 2018
1 parent 5401bd3 commit 6dbf4b5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
21 changes: 10 additions & 11 deletions pkg/commands/setimagetag.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,27 @@ and overwrite the previous ones if the image tag exists.
// Validate validates setImageTag command.
func (o *setImageTagOptions) Validate(args []string) error {
if len(args) == 0 {
return errors.New("no image and newTag specified")
return errors.New("no image specified")
}

o.imageTagMap = make(map[string]types.ImageTag)

for _, arg := range args {
if strings.Contains(arg, "@") {
img := strings.Split(arg, "@")
o.imageTagMap[img[0]] = types.ImageTag{
Name: img[0],
Digest: img[1],
if s := strings.Split(arg, "@"); len(s) > 1 {
o.imageTagMap[s[0]] = types.ImageTag{
Name: s[0],
Digest: s[1],
}
continue
}

imagetag := pattern.FindStringSubmatch(arg)
if len(imagetag) != 3 {
s := pattern.FindStringSubmatch(arg)
if len(s) != 3 {
return errors.New("invalid format of imagetag, must specify it as <image>:<newtag> or <image>@<digest>")
}
o.imageTagMap[imagetag[1]] = types.ImageTag{
Name: imagetag[1],
NewTag: imagetag[2],
o.imageTagMap[s[1]] = types.ImageTag{
Name: s[1],
NewTag: s[2],
}
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/setimagetag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestSetImageTagsNoArgs(t *testing.T) {
if err == nil {
t.Errorf("expected error: %v", err)
}
if err.Error() != "no image and newTag specified" {
if err.Error() != "no image specified" {
t.Errorf("incorrect error: %v", err.Error())
}
}

0 comments on commit 6dbf4b5

Please sign in to comment.