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{
"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"
}),
}
}
@ -41,12 +41,12 @@ func NewPauseCommand(dockerCli command.Cli) *cobra.Command {
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"))

View File

@ -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"
}),
}

View File

@ -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
@ -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"))

View File

@ -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"))

View File

@ -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())
}

View File

@ -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
}

View File

@ -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++
}
}
@ -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 {

View File

@ -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)
}

View File

@ -38,15 +38,15 @@ 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
},
},
@ -54,21 +54,21 @@ func TestNewInspectCommandSuccess(t *testing.T) {
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
},

View File

@ -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
}
}

View File

@ -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",
@ -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
@ -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)