cli/command/system: minor cleanups: use Println, rename vars

- use Println to print newline instead of custom format
- use dockerCLI with Go's standard camelCase casing.
- suppress some errors to make my IDE and linters happier

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-02-01 23:06:56 +01:00
parent 8c5e85d4cf
commit 5cfc89c1c2
2 changed files with 19 additions and 19 deletions

View File

@ -121,12 +121,12 @@ const rfc3339NanoFixed = "2006-01-02T15:04:05.000000000Z07:00"
// Actor attributes are printed at the end if the actor has any.
func prettyPrintEvent(out io.Writer, event events.Message) error {
if event.TimeNano != 0 {
fmt.Fprintf(out, "%s ", time.Unix(0, event.TimeNano).Format(rfc3339NanoFixed))
_, _ = fmt.Fprintf(out, "%s ", time.Unix(0, event.TimeNano).Format(rfc3339NanoFixed))
} else if event.Time != 0 {
fmt.Fprintf(out, "%s ", time.Unix(event.Time, 0).Format(rfc3339NanoFixed))
_, _ = fmt.Fprintf(out, "%s ", time.Unix(event.Time, 0).Format(rfc3339NanoFixed))
}
fmt.Fprintf(out, "%s %s %s", event.Type, event.Action, event.Actor.ID)
_, _ = fmt.Fprintf(out, "%s %s %s", event.Type, event.Action, event.Actor.ID)
if len(event.Actor.Attributes) > 0 {
var attrs []string
@ -139,9 +139,9 @@ func prettyPrintEvent(out io.Writer, event events.Message) error {
v := event.Actor.Attributes[k]
attrs = append(attrs, k+"="+v)
}
fmt.Fprintf(out, " (%s)", strings.Join(attrs, ", "))
_, _ = fmt.Fprintf(out, " (%s)", strings.Join(attrs, ", "))
}
fmt.Fprint(out, "\n")
_, _ = fmt.Fprint(out, "\n")
return nil
}

View File

@ -120,7 +120,7 @@ func inspectConfig(ctx context.Context, dockerCLI command.Cli) inspect.GetRefFun
}
}
func inspectAll(ctx context.Context, dockerCli command.Cli, getSize bool, typeConstraint string) inspect.GetRefFunc {
func inspectAll(ctx context.Context, dockerCLI command.Cli, getSize bool, typeConstraint string) inspect.GetRefFunc {
inspectAutodetect := []struct {
objectType string
isSizeSupported bool
@ -130,57 +130,57 @@ func inspectAll(ctx context.Context, dockerCli command.Cli, getSize bool, typeCo
{
objectType: "container",
isSizeSupported: true,
objectInspector: inspectContainers(ctx, dockerCli, getSize),
objectInspector: inspectContainers(ctx, dockerCLI, getSize),
},
{
objectType: "image",
objectInspector: inspectImages(ctx, dockerCli),
objectInspector: inspectImages(ctx, dockerCLI),
},
{
objectType: "network",
objectInspector: inspectNetwork(ctx, dockerCli),
objectInspector: inspectNetwork(ctx, dockerCLI),
},
{
objectType: "volume",
objectInspector: inspectVolume(ctx, dockerCli),
objectInspector: inspectVolume(ctx, dockerCLI),
},
{
objectType: "service",
isSwarmObject: true,
objectInspector: inspectService(ctx, dockerCli),
objectInspector: inspectService(ctx, dockerCLI),
},
{
objectType: "task",
isSwarmObject: true,
objectInspector: inspectTasks(ctx, dockerCli),
objectInspector: inspectTasks(ctx, dockerCLI),
},
{
objectType: "node",
isSwarmObject: true,
objectInspector: inspectNode(ctx, dockerCli),
objectInspector: inspectNode(ctx, dockerCLI),
},
{
objectType: "plugin",
objectInspector: inspectPlugin(ctx, dockerCli),
objectInspector: inspectPlugin(ctx, dockerCLI),
},
{
objectType: "secret",
isSwarmObject: true,
objectInspector: inspectSecret(ctx, dockerCli),
objectInspector: inspectSecret(ctx, dockerCLI),
},
{
objectType: "config",
isSwarmObject: true,
objectInspector: inspectConfig(ctx, dockerCli),
objectInspector: inspectConfig(ctx, dockerCLI),
},
}
// isSwarmManager does an Info API call to verify that the daemon is
// a swarm manager.
isSwarmManager := func() bool {
info, err := dockerCli.Client().Info(ctx)
info, err := dockerCLI.Client().Info(ctx)
if err != nil {
fmt.Fprintln(dockerCli.Err(), err)
_, _ = fmt.Fprintln(dockerCLI.Err(), err)
return false
}
return info.Swarm.ControlAvailable
@ -219,7 +219,7 @@ func inspectAll(ctx context.Context, dockerCli command.Cli, getSize bool, typeCo
return v, raw, err
}
if getSize && !inspectData.isSizeSupported {
fmt.Fprintf(dockerCli.Err(), "WARNING: --size ignored for %s\n", inspectData.objectType)
_, _ = fmt.Fprintln(dockerCLI.Err(), "WARNING: --size ignored for", inspectData.objectType)
}
return v, raw, err
}