Skip to content

Commit

Permalink
feat(cli): Show annotations in default discovery output
Browse files Browse the repository at this point in the history
Signed-off-by: Horiodino <holiodin@gmail.com>
  • Loading branch information
Horiodino committed Jan 8, 2025
1 parent e9c834d commit 1c1407e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 112 deletions.
3 changes: 0 additions & 3 deletions cmd/oras/internal/display/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"oras.land/oras/cmd/oras/internal/display/metadata"
"oras.land/oras/cmd/oras/internal/display/metadata/descriptor"
"oras.land/oras/cmd/oras/internal/display/metadata/json"
"oras.land/oras/cmd/oras/internal/display/metadata/maxtree"
"oras.land/oras/cmd/oras/internal/display/metadata/table"
"oras.land/oras/cmd/oras/internal/display/metadata/template"
"oras.land/oras/cmd/oras/internal/display/metadata/text"
Expand Down Expand Up @@ -118,8 +117,6 @@ func NewDiscoverHandler(out io.Writer, format option.Format, path string, rawRef
switch format.Type {
case option.FormatTypeTree.Name:
handler = tree.NewDiscoverHandler(out, path, desc, verbose)
case option.FormatTypeMaxTree.Name:
handler = maxtree.NewDiscoverHandler(out, path, desc, verbose)
case option.FormatTypeTable.Name:
handler = table.NewDiscoverHandler(out, rawReference, desc, verbose)
case option.FormatTypeJSON.Name:
Expand Down
92 changes: 0 additions & 92 deletions cmd/oras/internal/display/metadata/maxtree/discover.go

This file was deleted.

30 changes: 19 additions & 11 deletions cmd/oras/internal/display/metadata/tree/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (

"github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"gopkg.in/yaml.v3"
"oras.land/oras/cmd/oras/internal/display/metadata"
"oras.land/oras/internal/tree"
)
Expand Down Expand Up @@ -61,19 +60,28 @@ func (h *discoverHandler) OnDiscovered(referrer, subject ocispec.Descriptor) err
if !ok {
return fmt.Errorf("unexpected subject descriptor: %v", subject)
}
if referrer.ArtifactType == "" {
referrer.ArtifactType = "<unknown>"

referrerNode := node.AddPath(fmt.Sprintf("ArtifactType: %s", referrer.ArtifactType), fmt.Sprintf("Digest: %s", referrer.Digest))

referrerNode.AddPath(fmt.Sprintf("MediaType: %s", referrer.MediaType))
referrerNode.AddPath(fmt.Sprintf("Size: %d bytes", referrer.Size))
if len(referrer.URLs) > 0 {
referrerNode.AddPath(fmt.Sprintf("URLs: %s", strings.Join(referrer.URLs, ", ")))
}
if len(referrer.Data) > 0 {
referrerNode.AddPath(fmt.Sprintf("Data: %s", string(referrer.Data)))
}
referrerNode := node.AddPath(referrer.ArtifactType, referrer.Digest)
if h.verbose {
for k, v := range referrer.Annotations {
bytes, err := yaml.Marshal(map[string]string{k: v})
if err != nil {
return err
}
referrerNode.AddPath(strings.TrimSpace(string(bytes)))
if referrer.Platform != nil {
referrerNode.AddPath(fmt.Sprintf("Platform: OS=%s, Architecture=%s, OSVersion=%s, Variant=%s",
referrer.Platform.OS, referrer.Platform.Architecture, referrer.Platform.OSVersion, referrer.Platform.Variant))
if len(referrer.Platform.OSFeatures) > 0 {
referrerNode.AddPath(fmt.Sprintf("Platform OSFeatures: %s", strings.Join(referrer.Platform.OSFeatures, ", ")))
}
}
for k, v := range referrer.Annotations {
referrerNode.AddPath(fmt.Sprintf("Annotation: %s = %s", k, v))
}

h.nodes[referrer.Digest] = referrerNode
return nil
}
Expand Down
5 changes: 0 additions & 5 deletions cmd/oras/internal/option/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ var (
Name: "text",
Usage: "Print in text format",
}

FormatTypeMaxTree = &FormatType{
Name: "max-tree",
Usage: "Display a full tree view with detailed metadata output",
}
)

// Format contains input and parsed options for formatted output flags.
Expand Down
1 change: 0 additions & 1 deletion cmd/oras/root/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ Example - Discover referrers of the manifest tagged 'v1' in an OCI image layout
cmd.Flags().BoolVarP(&opts.verbose, "verbose", "v", false, "display full metadata of referrers")
opts.SetTypes(
option.FormatTypeTree,
option.FormatTypeMaxTree.WithUsage("Display a full tree view including indirect referrers with metadata"),
option.FormatTypeTable,
option.FormatTypeJSON.WithUsage("Get direct referrers and output in JSON format"),
option.FormatTypeGoTemplate.WithUsage("Print direct referrers using the given Go template"),
Expand Down

0 comments on commit 1c1407e

Please sign in to comment.