Skip to content

Commit

Permalink
rename vars to prevent colliding with imports
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastiaan van Stijn <[email protected]>
  • Loading branch information
thaJeztah committed Jul 3, 2024
1 parent 3a77fdd commit 42ba293
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 51 deletions.
8 changes: 4 additions & 4 deletions cli/command/container/pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ func NewPauseCommand(dockerCli command.Cli) *cobra.Command {
Annotations: map[string]string{
"aliases": "docker container pause, docker pause",
},
ValidArgsFunction: completion.ContainerNames(dockerCli, false, func(container types.Container) bool {
return container.State != "paused"
ValidArgsFunction: completion.ContainerNames(dockerCli, false, func(ctr types.Container) bool {
return ctr.State != "paused"
}),
}
}

func runPause(ctx context.Context, dockerCli command.Cli, opts *pauseOptions) error {
var errs []string
errChan := parallelOperation(ctx, opts.containers, dockerCli.Client().ContainerPause)
for _, container := range opts.containers {
for _, ctr := range opts.containers {
if err := <-errChan; err != nil {
errs = append(errs, err.Error())
continue
}
fmt.Fprintln(dockerCli.Out(), container)
_, _ = fmt.Fprintln(dockerCli.Out(), ctr)
}
if len(errs) > 0 {
return errors.New(strings.Join(errs, "\n"))
Expand Down
4 changes: 2 additions & 2 deletions cli/command/container/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func NewStartCommand(dockerCli command.Cli) *cobra.Command {
Annotations: map[string]string{
"aliases": "docker container start, docker start",
},
ValidArgsFunction: completion.ContainerNames(dockerCli, true, func(container types.Container) bool {
return container.State == "exited" || container.State == "created"
ValidArgsFunction: completion.ContainerNames(dockerCli, true, func(ctr types.Container) bool {
return ctr.State == "exited" || ctr.State == "created"
}),
}

Expand Down
8 changes: 4 additions & 4 deletions cli/command/container/unpause.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func NewUnpauseCommand(dockerCli command.Cli) *cobra.Command {
Annotations: map[string]string{
"aliases": "docker container unpause, docker unpause",
},
ValidArgsFunction: completion.ContainerNames(dockerCli, false, func(container types.Container) bool {
return container.State == "paused"
ValidArgsFunction: completion.ContainerNames(dockerCli, false, func(ctr types.Container) bool {
return ctr.State == "paused"
}),
}
return cmd
Expand All @@ -42,12 +42,12 @@ func NewUnpauseCommand(dockerCli command.Cli) *cobra.Command {
func runUnpause(ctx context.Context, dockerCli command.Cli, opts *unpauseOptions) error {
var errs []string
errChan := parallelOperation(ctx, opts.containers, dockerCli.Client().ContainerUnpause)
for _, container := range opts.containers {
for _, ctr := range opts.containers {
if err := <-errChan; err != nil {
errs = append(errs, err.Error())
continue
}
fmt.Fprintln(dockerCli.Out(), container)
_, _ = fmt.Fprintln(dockerCli.Out(), ctr)
}
if len(errs) > 0 {
return errors.New(strings.Join(errs, "\n"))
Expand Down
8 changes: 4 additions & 4 deletions cli/command/container/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,17 @@ func runUpdate(ctx context.Context, dockerCli command.Cli, options *updateOption
warns []string
errs []string
)
for _, container := range options.containers {
r, err := dockerCli.Client().ContainerUpdate(ctx, container, updateConfig)
for _, ctr := range options.containers {
r, err := dockerCli.Client().ContainerUpdate(ctx, ctr, updateConfig)
if err != nil {
errs = append(errs, err.Error())
} else {
fmt.Fprintln(dockerCli.Out(), container)
_, _ = fmt.Fprintln(dockerCli.Out(), ctr)
}
warns = append(warns, r.Warnings...)
}
if len(warns) > 0 {
fmt.Fprintln(dockerCli.Out(), strings.Join(warns, "\n"))
_, _ = fmt.Fprintln(dockerCli.Out(), strings.Join(warns, "\n"))
}
if len(errs) > 0 {
return errors.New(strings.Join(errs, "\n"))
Expand Down
6 changes: 3 additions & 3 deletions cli/command/container/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ func NewWaitCommand(dockerCli command.Cli) *cobra.Command {

func runWait(ctx context.Context, dockerCli command.Cli, opts *waitOptions) error {
var errs []string
for _, container := range opts.containers {
resultC, errC := dockerCli.Client().ContainerWait(ctx, container, "")
for _, ctr := range opts.containers {
resultC, errC := dockerCli.Client().ContainerWait(ctx, ctr, "")

select {
case result := <-resultC:
fmt.Fprintf(dockerCli.Out(), "%d\n", result.StatusCode)
_, _ = fmt.Fprintf(dockerCli.Out(), "%d\n", result.StatusCode)
case err := <-errC:
errs = append(errs, err.Error())
}
Expand Down
4 changes: 2 additions & 2 deletions cli/command/formatter/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ ports: {{- pad .Ports 1 0}}
// ContainerWrite renders the context for a list of containers
func ContainerWrite(ctx Context, containers []types.Container) error {
render := func(format func(subContext SubContext) error) error {
for _, container := range containers {
err := format(&ContainerContext{trunc: ctx.Trunc, c: container})
for _, ctr := range containers {
err := format(&ContainerContext{trunc: ctx.Trunc, c: ctr})
if err != nil {
return err
}
Expand Down
19 changes: 9 additions & 10 deletions cli/command/formatter/disk_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ func (c *diskUsageContainersContext) isActive(container types.Container) bool {

func (c *diskUsageContainersContext) Active() string {
used := 0
for _, container := range c.containers {
if c.isActive(*container) {
for _, ctr := range c.containers {
if c.isActive(*ctr) {
used++
}
}
Expand All @@ -348,22 +348,21 @@ func (c *diskUsageContainersContext) Active() string {
func (c *diskUsageContainersContext) Size() string {
var size int64

for _, container := range c.containers {
size += container.SizeRw
for _, ctr := range c.containers {
size += ctr.SizeRw
}

return units.HumanSize(float64(size))
}

func (c *diskUsageContainersContext) Reclaimable() string {
var reclaimable int64
var totalSize int64
var reclaimable, totalSize int64

for _, container := range c.containers {
if !c.isActive(*container) {
reclaimable += container.SizeRw
for _, ctr := range c.containers {
if !c.isActive(*ctr) {
reclaimable += ctr.SizeRw
}
totalSize += container.SizeRw
totalSize += ctr.SizeRw
}

if totalSize > 0 {
Expand Down
4 changes: 2 additions & 2 deletions cli/command/image/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ type fakeClient struct {
imagesPruneFunc func(pruneFilter filters.Args) (image.PruneReport, error)
imageLoadFunc func(input io.Reader, quiet bool) (image.LoadResponse, 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)
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)
}

Expand Down
16 changes: 8 additions & 8 deletions cli/command/image/inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,37 +38,37 @@ func TestNewInspectCommandSuccess(t *testing.T) {
name string
args []string
imageCount int
imageInspectFunc func(image string) (types.ImageInspect, []byte, error)
imageInspectFunc func(img string) (types.ImageInspect, []byte, error)
}{
{
name: "simple",
args: []string{"image"},
imageCount: 1,
imageInspectFunc: func(image string) (types.ImageInspect, []byte, error) {
imageInspectFunc: func(img string) (types.ImageInspect, []byte, error) {
imageInspectInvocationCount++
assert.Check(t, is.Equal("image", image))
assert.Check(t, is.Equal("image", img))
return types.ImageInspect{}, nil, nil
},
},
{
name: "format",
imageCount: 1,
args: []string{"--format='{{.ID}}'", "image"},
imageInspectFunc: func(image string) (types.ImageInspect, []byte, error) {
imageInspectFunc: func(img string) (types.ImageInspect, []byte, error) {
imageInspectInvocationCount++
return types.ImageInspect{ID: image}, nil, nil
return types.ImageInspect{ID: img}, nil, nil
},
},
{
name: "simple-many",
args: []string{"image1", "image2"},
imageCount: 2,
imageInspectFunc: func(image string) (types.ImageInspect, []byte, error) {
imageInspectFunc: func(img string) (types.ImageInspect, []byte, error) {
imageInspectInvocationCount++
if imageInspectInvocationCount == 1 {
assert.Check(t, is.Equal("image1", image))
assert.Check(t, is.Equal("image1", img))
} else {
assert.Check(t, is.Equal("image2", image))
assert.Check(t, is.Equal("image2", img))
}
return types.ImageInspect{}, nil, nil
},
Expand Down
10 changes: 5 additions & 5 deletions cli/command/network/disconnect.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@ func runDisconnect(ctx context.Context, dockerCli command.Cli, opts disconnectOp
}

func isConnected(network string) func(types.Container) bool {
return func(container types.Container) bool {
if container.NetworkSettings == nil {
return func(ctr types.Container) bool {
if ctr.NetworkSettings == nil {
return false
}
_, ok := container.NetworkSettings.Networks[network]
_, ok := ctr.NetworkSettings.Networks[network]
return ok
}
}

func not(fn func(types.Container) bool) func(types.Container) bool {
return func(container types.Container) bool {
ok := fn(container)
return func(ctr types.Container) bool {
ok := fn(ctr)
return !ok
}
}
14 changes: 7 additions & 7 deletions internal/test/builders/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (

// Container creates a container with default values.
// 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()
// onehourago := now.Add(-120 * time.Minute)
container := &types.Container{
ctr := &types.Container{
ID: "container_id",
Names: []string{"/" + name},
Command: "top",
Expand All @@ -21,10 +21,10 @@ func Container(name string, builders ...func(container *types.Container)) *types
}

for _, builder := range builders {
builder(container)
builder(ctr)
}

return container
return ctr
}

// WithLabel adds a label to the container
Expand All @@ -45,14 +45,14 @@ func WithName(name string) func(*types.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) {
if c.Ports == nil {
c.Ports = []types.Port{}
}
port := &types.Port{
PrivatePort: privateport,
PublicPort: publicport,
PrivatePort: privatePort,
PublicPort: publicPort,
}
for _, builder := range builders {
builder(port)
Expand Down

0 comments on commit 42ba293

Please sign in to comment.