Skip to content

Commit

Permalink
Support showing arch in tag list (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
FelicianoTech authored Sep 6, 2022
1 parent a4b91bb commit 1f6f4f8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 20 additions & 1 deletion sonar/cmd/tags_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"strings"
"time"

"github.com/felicianotech/sonar/sonar/docker"
Expand All @@ -11,6 +12,7 @@ import (

var (
sumSizeFl bool
archFl bool

tagsListCmd = &cobra.Command{
Use: "list <image-name>",
Expand Down Expand Up @@ -75,11 +77,27 @@ var (

var totalSize uint64

// This is where we actually output tags to display
for _, tag := range filteredTags {
fmt.Println(tag.Name)

fmt.Printf("%s", tag.Name)

if sumSizeFl {
totalSize += uint64(tag.Size)
}

if archFl {

var arches []string

for _, img := range tag.Images {
arches = append(arches, img.Arch)
}

fmt.Printf(" (%s)", strings.Join(arches, ","))
}

fmt.Printf("\n")
}

fmt.Println("====================")
Expand All @@ -95,6 +113,7 @@ var (

func init() {
tagsListCmd.Flags().BoolVar(&sumSizeFl, "sum-size", false, "output the storage size of tags")
tagsCmd.PersistentFlags().BoolVar(&archFl, "arch", false, "show CPU architectures available per tag. Defaults to false.")

tagsCmd.AddCommand(tagsListCmd)
}
2 changes: 2 additions & 0 deletions sonar/docker/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ func GetAllTags(imageStr string) ([]Tag, error) {
// return nil, err
//}

anImage.Arch = i.(map[string]interface{})["architecture"].(string)

if i.(map[string]interface{})["digest"] != nil {
anImage.Digest = i.(map[string]interface{})["digest"].(string)
}
Expand Down

0 comments on commit 1f6f4f8

Please sign in to comment.