Instead of printing out multiple lines for some steps in Layer section, now its only printing one line while other informations can be found in Layer details. This change also provides fix for index out of bounds error when user scrolls through steps in Layer section and there exists at least one step with multi-line commands.
46 lines
708 B
Go
46 lines
708 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) 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),
|
|
strings.Split(l.Command, "\n")[0])
|
|
}
|