summaryrefslogtreecommitdiffstats
path: root/dive/image/layer.go
blob: 550eba18fb81ae3156c25d5f6ad9b0c30533569e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package image

import (
	"fmt"
	"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),
		l.Command)
}