Skip to content

Commit ba25cc0

Browse files
committed
images command updates
Signed-off-by: Kyle Quest <kcq.public@gmail.com>
1 parent 7a77849 commit ba25cc0

File tree

2 files changed

+40
-9
lines changed

2 files changed

+40
-9
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Note that **DockerSlim** is now just **Slim** (**SlimToolkit** is the full name,
2323

2424
## Overview
2525

26-
Slim allows developers to inspect, optimize and debug their containers using its `xray`, `lint`, `build`, `debug`, `run`, `registry`, `vulnerability` (and other) commands. It simplifies and improves your developer experience building, customizing and using containers. It makes your containers better, smaller and more secure while providing advanced visibility and improved usability working with the original and minified containers.
26+
Slim allows developers to inspect, optimize and debug their containers using its `xray`, `lint`, `build`, `debug`, `run`, `images`, `merge`, `registry`, `vulnerability` (and other) commands. It simplifies and improves your developer experience building, customizing and using containers. It makes your containers better, smaller and more secure while providing advanced visibility and improved usability working with the original and minified containers.
2727

2828
Don't change anything in your container image and minify it by up to 30x making it secure too! Optimizing images isn't the only thing it can do though. It can also help you understand and author better container images.
2929

@@ -291,7 +291,7 @@ If you don't specify any command `slim` will start in the interactive prompt mod
291291
- `profile` - Performs basic container image analysis and dynamic container analysis, but it doesn't generate an optimized image.
292292
- `run` - Runs one or more containers (for now runs a single container similar to `docker run`)
293293
- `merge` - Merge two container images (optimized to merge minified images).
294-
- `images` - Get information about container images.
294+
- `images` - Get information about container images (example: `slim --quiet images`).
295295
- `vulnerability` - Execute vulnerability related tools and operations (`epss`).
296296
- `version` - Shows the version information.
297297
- `appbom` - Shows the application BOM (app composition/dependencies).

pkg/app/master/command/images/handler.go

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package images
22

33
import (
4+
"fmt"
45
"time"
56

67
"github.com/dustin/go-humanize"
8+
"github.com/jedib0t/go-pretty/v6/table"
79
log "github.com/sirupsen/logrus"
810

911
"github.com/slimtoolkit/slim/pkg/app"
@@ -14,6 +16,7 @@ import (
1416
"github.com/slimtoolkit/slim/pkg/docker/dockerutil"
1517
"github.com/slimtoolkit/slim/pkg/report"
1618
"github.com/slimtoolkit/slim/pkg/util/fsutil"
19+
"github.com/slimtoolkit/slim/pkg/util/jsonutil"
1720
v "github.com/slimtoolkit/slim/pkg/version"
1821
)
1922

@@ -69,15 +72,25 @@ func OnCommand(
6972
images, err := dockerutil.ListImages(client, "")
7073
xc.FailOn(err)
7174

72-
for name, info := range images {
73-
fields := ovars{
74-
"name": name,
75-
"id": info.ID,
76-
"size": humanize.Bytes(uint64(info.Size)),
77-
"created": time.Unix(info.Created, 0).Format(time.RFC3339),
75+
if xc.Out.Quiet {
76+
if xc.Out.OutputFormat == command.OutputFormatJSON {
77+
fmt.Printf("%s\n", jsonutil.ToPretty(images))
78+
return
7879
}
7980

80-
xc.Out.Info("image", fields)
81+
printImagesTable(images)
82+
return
83+
} else {
84+
for name, info := range images {
85+
fields := ovars{
86+
"name": name,
87+
"id": info.ID,
88+
"size": humanize.Bytes(uint64(info.Size)),
89+
"created": time.Unix(info.Created, 0).Format(time.RFC3339),
90+
}
91+
92+
xc.Out.Info("image", fields)
93+
}
8194
}
8295

8396
xc.Out.State("completed")
@@ -95,3 +108,21 @@ func OnCommand(
95108
})
96109
}
97110
}
111+
112+
func printImagesTable(images map[string]dockerutil.BasicImageProps) {
113+
tw := table.NewWriter()
114+
tw.AppendHeader(table.Row{"Name", "ID", "Size", "Created"})
115+
116+
for name, info := range images {
117+
tw.AppendRow(table.Row{
118+
name,
119+
info.ID,
120+
humanize.Bytes(uint64(info.Size)),
121+
time.Unix(info.Created, 0).Format(time.RFC3339),
122+
})
123+
}
124+
125+
tw.SetStyle(table.StyleLight)
126+
tw.Style().Options.DrawBorder = false
127+
fmt.Printf("%s\n", tw.Render())
128+
}

0 commit comments

Comments
 (0)