dive/dive/image/layer.go
Alex Goodman d5e8a92968
Rework CI validation workflow and makefile (#460)
* rework CI validation workflow and makefile

* enable push

* fix job names

* fix license check

* fix snapshot builds

* fix acceptance tests

* fix linting

* disable pull request event

* rework windows runner caching

* disable release pipeline and add issue templates
2023-07-06 22:01:46 -04:00

53 lines
898 B
Go

package image
import (
"fmt"
"strings"
"github.com/dustin/go-humanize"
"github.com/wagoodman/dive/dive/filetree"
)
const (
LayerFormat = "%7s %s"
)
type Layer struct {
Id string
Index int
Command string
Size uint64
Tree *filetree.FileTree
Names []string
Digest string
}
func (l *Layer) ShortId() string {
rangeBound := 15
id := l.Id
if length := len(id); length < 15 {
rangeBound = length
}
id = id[0:rangeBound]
return id
}
func (l *Layer) commandPreview() string {
// Layers using heredocs can be multiple lines; rendering relies on
// Layer.String to be a single line.
return strings.Replace(l.Command, "\n", "↵", -1)
}
func (l *Layer) String() string {
if l.Index == 0 {
return fmt.Sprintf(LayerFormat,
humanize.Bytes(l.Size),
"FROM "+l.ShortId())
}
return fmt.Sprintf(LayerFormat,
humanize.Bytes(l.Size),
l.commandPreview())
}