Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 88f1e6a

Browse files
committedMar 15, 2025··
show annotations in default discovery output
Signed-off-by: Horiodino <[email protected]>
1 parent 474e2de commit 88f1e6a

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed
 

‎cmd/oras/internal/display/metadata/tree/discover.go

+12
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"io"
2121
"strings"
2222

23+
"github.com/fatih/color"
2324
"github.com/opencontainers/go-digest"
2425
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2526
"gopkg.in/yaml.v3"
@@ -74,6 +75,17 @@ func (h *discoverHandler) OnDiscovered(referrer, subject ocispec.Descriptor) err
7475
referrerNode.AddPath(strings.TrimSpace(string(bytes)))
7576
}
7677
}
78+
79+
if len(referrer.Annotations) > 0 {
80+
annotationsNode := referrerNode.Add("[annotations]")
81+
82+
for k, v := range referrer.Annotations {
83+
coloredAnnotation := color.New(color.FgYellow).Sprintf("%s: %s", k, v)
84+
annotationsNode.Add(coloredAnnotation)
85+
}
86+
} else {
87+
referrerNode.Add(color.New(color.FgYellow).Sprint("[annotations] None"))
88+
}
7789
h.nodes[referrer.Digest] = referrerNode
7890
return nil
7991
}

‎go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.24.0
55
require (
66
github.com/Masterminds/sprig/v3 v3.3.0
77
github.com/containerd/console v1.0.4
8+
github.com/fatih/color v1.18.0
89
github.com/morikuni/aec v1.0.0
910
github.com/opencontainers/go-digest v1.0.0
1011
github.com/opencontainers/image-spec v1.1.1
@@ -24,6 +25,8 @@ require (
2425
github.com/google/uuid v1.6.0 // indirect
2526
github.com/huandu/xstrings v1.5.0 // indirect
2627
github.com/inconshreveable/mousetrap v1.1.0 // indirect
28+
github.com/mattn/go-colorable v0.1.13 // indirect
29+
github.com/mattn/go-isatty v0.0.20 // indirect
2730
github.com/mitchellh/copystructure v1.2.0 // indirect
2831
github.com/mitchellh/reflectwalk v1.0.2 // indirect
2932
github.com/shopspring/decimal v1.4.0 // indirect

‎go.sum

+8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6N
1212
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1313
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1414
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
15+
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
16+
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
1517
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
1618
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
1719
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
@@ -26,6 +28,11 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
2628
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
2729
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
2830
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
31+
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
32+
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
33+
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
34+
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
35+
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
2936
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
3037
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
3138
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
@@ -59,6 +66,7 @@ golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ss
5966
golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw=
6067
golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
6168
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
69+
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
6270
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
6371
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
6472
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=

0 commit comments

Comments
 (0)
Please sign in to comment.