rename vars to prevent colliding with imports

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2024-07-03 16:14:40 +02:00
parent 3a77fdd91f
commit 42ba29395b
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
11 changed files with 50 additions and 51 deletions

View File

@ -32,8 +32,8 @@ func NewPauseCommand(dockerCli command.Cli) *cobra.Command {
Annotations: map[string]string{ Annotations: map[string]string{
"aliases": "docker container pause, docker pause", "aliases": "docker container pause, docker pause",
}, },
ValidArgsFunction: completion.ContainerNames(dockerCli, false, func(container types.Container) bool { ValidArgsFunction: completion.ContainerNames(dockerCli, false, func(ctr types.Container) bool {
return container.State != "paused" return ctr.State != "paused"
}), }),
} }
} }
@ -41,12 +41,12 @@ func NewPauseCommand(dockerCli command.Cli) *cobra.Command {
func runPause(ctx context.Context, dockerCli command.Cli, opts *pauseOptions) error { func runPause(ctx context.Context, dockerCli command.Cli, opts *pauseOptions) error {
var errs []string var errs []string
errChan := parallelOperation(ctx, opts.containers, dockerCli.Client().ContainerPause) errChan := parallelOperation(ctx, opts.containers, dockerCli.Client().ContainerPause)
for _, container := range opts.containers { for _, ctr := range opts.containers {
if err := <-errChan; err != nil { if err := <-errChan; err != nil {
errs = append(errs, err.Error()) errs = append(errs, err.Error())
continue continue
} }
fmt.Fprintln(dockerCli.Out(), container) _, _ = fmt.Fprintln(dockerCli.Out(), ctr)
} }
if len(errs) > 0 { if len(errs) > 0 {
return errors.New(strings.Join(errs, "\n")) return errors.New(strings.Join(errs, "\n"))

View File

@ -43,8 +43,8 @@ func NewStartCommand(dockerCli command.Cli) *cobra.Command {
Annotations: map[string]string{ Annotations: map[string]string{
"aliases": "docker container start, docker start", "aliases": "docker container start, docker start",
}, },
ValidArgsFunction: completion.ContainerNames(dockerCli, true, func(container types.Container) bool { ValidArgsFunction: completion.ContainerNames(dockerCli, true, func(ctr types.Container) bool {
return container.State == "exited" || container.State == "created" return ctr.State == "exited" || ctr.State == "created"
}), }),
} }

View File

@ -32,8 +32,8 @@ func NewUnpauseCommand(dockerCli command.Cli) *cobra.Command {
Annotations: map[string]string{ Annotations: map[string]string{
"aliases": "docker container unpause, docker unpause", "aliases": "docker container unpause, docker unpause",
}, },
ValidArgsFunction: completion.ContainerNames(dockerCli, false, func(container types.Container) bool { ValidArgsFunction: completion.ContainerNames(dockerCli, false, func(ctr types.Container) bool {
return container.State == "paused" return ctr.State == "paused"
}), }),
} }
return cmd return cmd
@ -42,12 +42,12 @@ func NewUnpauseCommand(dockerCli command.Cli) *cobra.Command {
func runUnpause(ctx context.Context, dockerCli command.Cli, opts *unpauseOptions) error { func runUnpause(ctx context.Context, dockerCli command.Cli, opts *unpauseOptions) error {
var errs []string var errs []string
errChan := parallelOperation(ctx, opts.containers, dockerCli.Client().ContainerUnpause) errChan := parallelOperation(ctx, opts.containers, dockerCli.Client().ContainerUnpause)
for _, container := range opts.containers { for _, ctr := range opts.containers {
if err := <-errChan; err != nil { if err := <-errChan; err != nil {
errs = append(errs, err.Error()) errs = append(errs, err.Error())
continue continue
} }
fmt.Fprintln(dockerCli.Out(), container) _, _ = fmt.Fprintln(dockerCli.Out(), ctr)
} }
if len(errs) > 0 { if len(errs) > 0 {
return errors.New(strings.Join(errs, "\n")) return errors.New(strings.Join(errs, "\n"))

View File

@ -130,17 +130,17 @@ func runUpdate(ctx context.Context, dockerCli command.Cli, options *updateOption
warns []string warns []string
errs []string errs []string
) )
for _, container := range options.containers { for _, ctr := range options.containers {
r, err := dockerCli.Client().ContainerUpdate(ctx, container, updateConfig) r, err := dockerCli.Client().ContainerUpdate(ctx, ctr, updateConfig)
if err != nil { if err != nil {
errs = append(errs, err.Error()) errs = append(errs, err.Error())
} else { } else {
fmt.Fprintln(dockerCli.Out(), container) _, _ = fmt.Fprintln(dockerCli.Out(), ctr)
} }
warns = append(warns, r.Warnings...) warns = append(warns, r.Warnings...)
} }
if len(warns) > 0 { if len(warns) > 0 {
fmt.Fprintln(dockerCli.Out(), strings.Join(warns, "\n")) _, _ = fmt.Fprintln(dockerCli.Out(), strings.Join(warns, "\n"))
} }
if len(errs) > 0 { if len(errs) > 0 {
return errors.New(strings.Join(errs, "\n")) return errors.New(strings.Join(errs, "\n"))

View File

@ -39,12 +39,12 @@ func NewWaitCommand(dockerCli command.Cli) *cobra.Command {
func runWait(ctx context.Context, dockerCli command.Cli, opts *waitOptions) error { func runWait(ctx context.Context, dockerCli command.Cli, opts *waitOptions) error {
var errs []string var errs []string
for _, container := range opts.containers { for _, ctr := range opts.containers {
resultC, errC := dockerCli.Client().ContainerWait(ctx, container, "") resultC, errC := dockerCli.Client().ContainerWait(ctx, ctr, "")
select { select {
case result := <-resultC: case result := <-resultC:
fmt.Fprintf(dockerCli.Out(), "%d\n", result.StatusCode) _, _ = fmt.Fprintf(dockerCli.Out(), "%d\n", result.StatusCode)
case err := <-errC: case err := <-errC:
errs = append(errs, err.Error()) errs = append(errs, err.Error())
} }

View File

@ -68,8 +68,8 @@ ports: {{- pad .Ports 1 0}}
// ContainerWrite renders the context for a list of containers // ContainerWrite renders the context for a list of containers
func ContainerWrite(ctx Context, containers []types.Container) error { func ContainerWrite(ctx Context, containers []types.Container) error {
render := func(format func(subContext SubContext) error) error { render := func(format func(subContext SubContext) error) error {
for _, container := range containers { for _, ctr := range containers {
err := format(&ContainerContext{trunc: ctx.Trunc, c: container}) err := format(&ContainerContext{trunc: ctx.Trunc, c: ctr})
if err != nil { if err != nil {
return err return err
} }

View File

@ -336,8 +336,8 @@ func (c *diskUsageContainersContext) isActive(container types.Container) bool {
func (c *diskUsageContainersContext) Active() string { func (c *diskUsageContainersContext) Active() string {
used := 0 used := 0
for _, container := range c.containers { for _, ctr := range c.containers {
if c.isActive(*container) { if c.isActive(*ctr) {
used++ used++
} }
} }
@ -348,22 +348,21 @@ func (c *diskUsageContainersContext) Active() string {
func (c *diskUsageContainersContext) Size() string { func (c *diskUsageContainersContext) Size() string {
var size int64 var size int64
for _, container := range c.containers { for _, ctr := range c.containers {
size += container.SizeRw size += ctr.SizeRw
} }
return units.HumanSize(float64(size)) return units.HumanSize(float64(size))
} }
func (c *diskUsageContainersContext) Reclaimable() string { func (c *diskUsageContainersContext) Reclaimable() string {
var reclaimable int64 var reclaimable, totalSize int64
var totalSize int64
for _, container := range c.containers { for _, ctr := range c.containers {
if !c.isActive(*container) { if !c.isActive(*ctr) {
reclaimable += container.SizeRw reclaimable += ctr.SizeRw
} }
totalSize += container.SizeRw totalSize += ctr.SizeRw
} }
if totalSize > 0 { if totalSize > 0 {

View File

@ -24,9 +24,9 @@ type fakeClient struct {
imagesPruneFunc func(pruneFilter filters.Args) (image.PruneReport, error) imagesPruneFunc func(pruneFilter filters.Args) (image.PruneReport, error)
imageLoadFunc func(input io.Reader, quiet bool) (image.LoadResponse, error) imageLoadFunc func(input io.Reader, quiet bool) (image.LoadResponse, error)
imageListFunc func(options image.ListOptions) ([]image.Summary, error) imageListFunc func(options image.ListOptions) ([]image.Summary, error)
imageInspectFunc func(image string) (types.ImageInspect, []byte, error) imageInspectFunc func(img string) (types.ImageInspect, []byte, error)
imageImportFunc func(source image.ImportSource, ref string, options image.ImportOptions) (io.ReadCloser, error) imageImportFunc func(source image.ImportSource, ref string, options image.ImportOptions) (io.ReadCloser, error)
imageHistoryFunc func(image string) ([]image.HistoryResponseItem, error) imageHistoryFunc func(img string) ([]image.HistoryResponseItem, error)
imageBuildFunc func(context.Context, io.Reader, types.ImageBuildOptions) (types.ImageBuildResponse, error) imageBuildFunc func(context.Context, io.Reader, types.ImageBuildOptions) (types.ImageBuildResponse, error)
} }

View File

@ -38,15 +38,15 @@ func TestNewInspectCommandSuccess(t *testing.T) {
name string name string
args []string args []string
imageCount int imageCount int
imageInspectFunc func(image string) (types.ImageInspect, []byte, error) imageInspectFunc func(img string) (types.ImageInspect, []byte, error)
}{ }{
{ {
name: "simple", name: "simple",
args: []string{"image"}, args: []string{"image"},
imageCount: 1, imageCount: 1,
imageInspectFunc: func(image string) (types.ImageInspect, []byte, error) { imageInspectFunc: func(img string) (types.ImageInspect, []byte, error) {
imageInspectInvocationCount++ imageInspectInvocationCount++
assert.Check(t, is.Equal("image", image)) assert.Check(t, is.Equal("image", img))
return types.ImageInspect{}, nil, nil return types.ImageInspect{}, nil, nil
}, },
}, },
@ -54,21 +54,21 @@ func TestNewInspectCommandSuccess(t *testing.T) {
name: "format", name: "format",
imageCount: 1, imageCount: 1,
args: []string{"--format='{{.ID}}'", "image"}, args: []string{"--format='{{.ID}}'", "image"},
imageInspectFunc: func(image string) (types.ImageInspect, []byte, error) { imageInspectFunc: func(img string) (types.ImageInspect, []byte, error) {
imageInspectInvocationCount++ imageInspectInvocationCount++
return types.ImageInspect{ID: image}, nil, nil return types.ImageInspect{ID: img}, nil, nil
}, },
}, },
{ {
name: "simple-many", name: "simple-many",
args: []string{"image1", "image2"}, args: []string{"image1", "image2"},
imageCount: 2, imageCount: 2,
imageInspectFunc: func(image string) (types.ImageInspect, []byte, error) { imageInspectFunc: func(img string) (types.ImageInspect, []byte, error) {
imageInspectInvocationCount++ imageInspectInvocationCount++
if imageInspectInvocationCount == 1 { if imageInspectInvocationCount == 1 {
assert.Check(t, is.Equal("image1", image)) assert.Check(t, is.Equal("image1", img))
} else { } else {
assert.Check(t, is.Equal("image2", image)) assert.Check(t, is.Equal("image2", img))
} }
return types.ImageInspect{}, nil, nil return types.ImageInspect{}, nil, nil
}, },

View File

@ -50,18 +50,18 @@ func runDisconnect(ctx context.Context, dockerCli command.Cli, opts disconnectOp
} }
func isConnected(network string) func(types.Container) bool { func isConnected(network string) func(types.Container) bool {
return func(container types.Container) bool { return func(ctr types.Container) bool {
if container.NetworkSettings == nil { if ctr.NetworkSettings == nil {
return false return false
} }
_, ok := container.NetworkSettings.Networks[network] _, ok := ctr.NetworkSettings.Networks[network]
return ok return ok
} }
} }
func not(fn func(types.Container) bool) func(types.Container) bool { func not(fn func(types.Container) bool) func(types.Container) bool {
return func(container types.Container) bool { return func(ctr types.Container) bool {
ok := fn(container) ok := fn(ctr)
return !ok return !ok
} }
} }

View File

@ -8,10 +8,10 @@ import (
// Container creates a container with default values. // Container creates a container with default values.
// Any number of container function builder can be passed to augment it. // Any number of container function builder can be passed to augment it.
func Container(name string, builders ...func(container *types.Container)) *types.Container { func Container(name string, builders ...func(c *types.Container)) *types.Container {
// now := time.Now() // now := time.Now()
// onehourago := now.Add(-120 * time.Minute) // onehourago := now.Add(-120 * time.Minute)
container := &types.Container{ ctr := &types.Container{
ID: "container_id", ID: "container_id",
Names: []string{"/" + name}, Names: []string{"/" + name},
Command: "top", Command: "top",
@ -21,10 +21,10 @@ func Container(name string, builders ...func(container *types.Container)) *types
} }
for _, builder := range builders { for _, builder := range builders {
builder(container) builder(ctr)
} }
return container return ctr
} }
// WithLabel adds a label to the container // WithLabel adds a label to the container
@ -45,14 +45,14 @@ func WithName(name string) func(*types.Container) {
} }
// WithPort adds a port mapping to the container // WithPort adds a port mapping to the container
func WithPort(privateport, publicport uint16, builders ...func(*types.Port)) func(*types.Container) { func WithPort(privatePort, publicPort uint16, builders ...func(*types.Port)) func(*types.Container) {
return func(c *types.Container) { return func(c *types.Container) {
if c.Ports == nil { if c.Ports == nil {
c.Ports = []types.Port{} c.Ports = []types.Port{}
} }
port := &types.Port{ port := &types.Port{
PrivatePort: privateport, PrivatePort: privatePort,
PublicPort: publicport, PublicPort: publicPort,
} }
for _, builder := range builders { for _, builder := range builders {
builder(port) builder(port)