mirror of https://github.com/docker/cli.git
Compare commits
8 Commits
fa0bad91ba
...
0f0f4b7a98
Author | SHA1 | Date |
---|---|---|
Paweł Gronowski | 0f0f4b7a98 | |
Sebastiaan van Stijn | a5fb752ecf | |
Laura Brehm | 4e64c59d64 | |
Jonathan A. Sternberg | 3472bbc28a | |
Laura Brehm | 649e564ee0 | |
Sebastiaan van Stijn | e1213edcc6 | |
Jonathan A. Sternberg | b1956f5073 | |
Paweł Gronowski | 54a4ab135f |
|
@ -67,7 +67,7 @@ jobs:
|
||||||
name: Update Go
|
name: Update Go
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: '1.21'
|
go-version: 1.22.7
|
||||||
-
|
-
|
||||||
name: Initialize CodeQL
|
name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@v3
|
uses: github/codeql-action/init@v3
|
||||||
|
|
|
@ -3,6 +3,7 @@ package image
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
@ -25,6 +26,9 @@ type treeOptions struct {
|
||||||
type treeView struct {
|
type treeView struct {
|
||||||
images []topImage
|
images []topImage
|
||||||
|
|
||||||
|
// showUsed indicates whether the "Used" column should be shown.
|
||||||
|
showUsed bool
|
||||||
|
|
||||||
// imageSpacing indicates whether there should be extra spacing between images.
|
// imageSpacing indicates whether there should be extra spacing between images.
|
||||||
imageSpacing bool
|
imageSpacing bool
|
||||||
}
|
}
|
||||||
|
@ -71,6 +75,9 @@ func runTree(ctx context.Context, dockerCLI command.Cli, opts treeOptions) error
|
||||||
if sub.Details.Used {
|
if sub.Details.Used {
|
||||||
// Mark top-level parent image as used if any of its subimages are used.
|
// Mark top-level parent image as used if any of its subimages are used.
|
||||||
details.Used = true
|
details.Used = true
|
||||||
|
|
||||||
|
// Show the Used column only if there will be at least one non-zero value.
|
||||||
|
view.showUsed = true
|
||||||
}
|
}
|
||||||
|
|
||||||
totalContent += im.Size.Content
|
totalContent += im.Size.Content
|
||||||
|
@ -192,6 +199,12 @@ func printImageTree(dockerCLI command.Cli, view treeView) error {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !view.showUsed {
|
||||||
|
columns = slices.DeleteFunc(columns, func(c imgColumn) bool {
|
||||||
|
return c.Title == "Used"
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
nameWidth := int(width)
|
nameWidth := int(width)
|
||||||
for idx, h := range columns {
|
for idx, h := range columns {
|
||||||
if h.Width == 0 {
|
if h.Width == 0 {
|
||||||
|
|
|
@ -180,7 +180,7 @@ func toWslPath(s string) string {
|
||||||
if !ok {
|
if !ok {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("mnt/%s%s", drive, p)
|
return fmt.Sprintf("mnt/%s%s", strings.ToLower(drive), p)
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseUNCPath(s string) (drive, p string, ok bool) {
|
func parseUNCPath(s string) (drive, p string, ok bool) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package command
|
package command
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/fs"
|
||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
"testing/fstest"
|
"testing/fstest"
|
||||||
|
@ -9,21 +10,48 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestWslSocketPath(t *testing.T) {
|
func TestWslSocketPath(t *testing.T) {
|
||||||
u, err := url.Parse("unix:////./c:/my/file/path")
|
testCases := []struct {
|
||||||
assert.NilError(t, err)
|
doc string
|
||||||
|
fs fs.FS
|
||||||
|
url string
|
||||||
|
expected string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
doc: "filesystem where WSL path does not exist",
|
||||||
|
fs: fstest.MapFS{
|
||||||
|
"my/file/path": {},
|
||||||
|
},
|
||||||
|
url: "unix:////./c:/my/file/path",
|
||||||
|
expected: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
doc: "filesystem where WSL path exists",
|
||||||
|
fs: fstest.MapFS{
|
||||||
|
"mnt/c/my/file/path": {},
|
||||||
|
},
|
||||||
|
url: "unix:////./c:/my/file/path",
|
||||||
|
expected: "/mnt/c/my/file/path",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
doc: "filesystem where WSL path exists uppercase URL",
|
||||||
|
fs: fstest.MapFS{
|
||||||
|
"mnt/c/my/file/path": {},
|
||||||
|
},
|
||||||
|
url: "unix:////./C:/my/file/path",
|
||||||
|
expected: "/mnt/c/my/file/path",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range testCases {
|
||||||
|
t.Run(tc.doc, func(t *testing.T) {
|
||||||
|
u, err := url.Parse(tc.url)
|
||||||
|
assert.NilError(t, err)
|
||||||
// Ensure host is empty.
|
// Ensure host is empty.
|
||||||
assert.Equal(t, u.Host, "")
|
assert.Equal(t, u.Host, "")
|
||||||
|
|
||||||
// Use a filesystem where the WSL path exists.
|
result := wslSocketPath(u.Path, tc.fs)
|
||||||
fs := fstest.MapFS{
|
|
||||||
"mnt/c/my/file/path": {},
|
|
||||||
}
|
|
||||||
assert.Equal(t, wslSocketPath(u.Path, fs), "/mnt/c/my/file/path")
|
|
||||||
|
|
||||||
// Use a filesystem where the WSL path doesn't exist.
|
assert.Equal(t, result, tc.expected)
|
||||||
fs = fstest.MapFS{
|
})
|
||||||
"my/file/path": {},
|
|
||||||
}
|
}
|
||||||
assert.Equal(t, wslSocketPath(u.Path, fs), "")
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"github.com/docker/cli/cli/version"
|
"github.com/docker/cli/cli/version"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"go.opentelemetry.io/otel"
|
||||||
"go.opentelemetry.io/otel/attribute"
|
"go.opentelemetry.io/otel/attribute"
|
||||||
"go.opentelemetry.io/otel/metric"
|
"go.opentelemetry.io/otel/metric"
|
||||||
)
|
)
|
||||||
|
@ -94,7 +95,9 @@ func startCobraCommandTimer(mp metric.MeterProvider, attrs []attribute.KeyValue)
|
||||||
metric.WithAttributes(cmdStatusAttrs...),
|
metric.WithAttributes(cmdStatusAttrs...),
|
||||||
)
|
)
|
||||||
if mp, ok := mp.(MeterProvider); ok {
|
if mp, ok := mp.(MeterProvider); ok {
|
||||||
mp.ForceFlush(ctx)
|
if err := mp.ForceFlush(ctx); err != nil {
|
||||||
|
otel.Handle(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -358,7 +358,9 @@ func runDocker(ctx context.Context, dockerCli *command.DockerCli) error {
|
||||||
|
|
||||||
mp := dockerCli.MeterProvider()
|
mp := dockerCli.MeterProvider()
|
||||||
if mp, ok := mp.(command.MeterProvider); ok {
|
if mp, ok := mp.(command.MeterProvider); ok {
|
||||||
defer mp.Shutdown(ctx)
|
if err := mp.Shutdown(ctx); err != nil {
|
||||||
|
otel.Handle(err)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprint(dockerCli.Err(), "Warning: Unexpected OTEL error, metrics may not be flushed")
|
fmt.Fprint(dockerCli.Err(), "Warning: Unexpected OTEL error, metrics may not be flushed")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue