summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOhad Lutzky <lutzky@gmail.com>2023-04-14 13:39:06 +0100
committerAlex Goodman <wagoodman@users.noreply.github.com>2023-07-06 10:48:06 -0400
commitceb9688d9289e185b925f8e7447f5dd2a326fd29 (patch)
tree9ff644a952588033cda51a813a6c7f4f9a3d4046
parent2a99dd25fe6490a3918221d5f084e71a6349ad5f (diff)
Fix rendering for multi-line commands
Heredocs can be used to create multi-line commands, which broke rendering. Details about heredocs: https://www.docker.com/blog/introduction-to-heredocs-in-dockerfiles/
-rw-r--r--dive/image/layer.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/dive/image/layer.go b/dive/image/layer.go
index ac96363..8c7fa6a 100644
--- a/dive/image/layer.go
+++ b/dive/image/layer.go
@@ -33,6 +33,12 @@ func (l *Layer) ShortId() string {
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,
@@ -41,5 +47,5 @@ func (l *Layer) String() string {
}
return fmt.Sprintf(LayerFormat,
humanize.Bytes(l.Size),
- strings.Split(l.Command, "\n")[0])
+ l.commandPreview())
}