Skip to content

Commit

Permalink
refactor: Move descriptor logic to descriptor (#1413)
Browse files Browse the repository at this point in the history
Signed-off-by: Terry Howe <[email protected]>
Co-authored-by: Billy Zha <[email protected]>
  • Loading branch information
Terry Howe and qweeah authored Jun 18, 2024
1 parent a84af2f commit 294abbc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
10 changes: 3 additions & 7 deletions cmd/oras/internal/output/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,9 @@ func (p *Printer) PrintVerbose(a ...any) error {

// PrintStatus prints transfer status.
func (p *Printer) PrintStatus(desc ocispec.Descriptor, status string) error {
name, ok := desc.Annotations[ocispec.AnnotationTitle]
if !ok {
// no status for unnamed content
if !p.verbose {
return nil
}
name = desc.MediaType
name, isTitle := descriptor.GetTitleOrMediaType(desc)
if !isTitle {
return p.PrintVerbose(status, descriptor.ShortDigest(desc), name)
}
return p.Println(status, descriptor.ShortDigest(desc), name)
}
Expand Down
9 changes: 9 additions & 0 deletions internal/descriptor/descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,12 @@ func ShortDigest(desc ocispec.Descriptor) (digestString string) {
}
return digestString
}

// GetTitleOrMediaType gets a descriptor name using either title or media type.
func GetTitleOrMediaType(desc ocispec.Descriptor) (name string, isTitle bool) {
name, ok := desc.Annotations[ocispec.AnnotationTitle]
if !ok {
return desc.MediaType, false
}
return name, true
}

0 comments on commit 294abbc

Please sign in to comment.