Skip to content

Commit 2d0ea86

Browse files
committed
cli/command/system: use io.Writer for printing warnings
Don't require whole of DockerCLI to be passed, as all we need is a writer. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent be6f4cd commit 2d0ea86

1 file changed

Lines changed: 18 additions & 19 deletions

File tree

cli/command/system/info.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,7 @@ func prettyPrintServerInfo(dockerCli command.Cli, info *info) []error {
366366
}
367367

368368
fmt.Fprint(dockerCli.Out(), "\n")
369-
370-
printServerWarnings(dockerCli, info)
369+
printServerWarnings(dockerCli.Err(), info)
371370
return errs
372371
}
373372

@@ -441,16 +440,16 @@ func printSwarmInfo(dockerCli command.Cli, info types.Info) {
441440
}
442441
}
443442

444-
func printServerWarnings(dockerCli command.Cli, info *info) {
443+
func printServerWarnings(stdErr io.Writer, info *info) {
445444
if versions.LessThan(info.ClientInfo.APIVersion, "1.42") {
446-
printSecurityOptionsWarnings(dockerCli, *info.Info)
445+
printSecurityOptionsWarnings(stdErr, *info.Info)
447446
}
448447
if len(info.Warnings) > 0 {
449-
fmt.Fprintln(dockerCli.Err(), strings.Join(info.Warnings, "\n"))
448+
fmt.Fprintln(stdErr, strings.Join(info.Warnings, "\n"))
450449
return
451450
}
452451
// daemon didn't return warnings. Fallback to old behavior
453-
printServerWarningsLegacy(dockerCli, *info.Info)
452+
printServerWarningsLegacy(stdErr, *info.Info)
454453
}
455454

456455
// printSecurityOptionsWarnings prints warnings based on the security options
@@ -459,7 +458,7 @@ func printServerWarnings(dockerCli command.Cli, info *info) {
459458
// info.Warnings. This function is used to provide backward compatibility with
460459
// daemons that do not provide these warnings. No new warnings should be added
461460
// here.
462-
func printSecurityOptionsWarnings(dockerCli command.Cli, info types.Info) {
461+
func printSecurityOptionsWarnings(stdErr io.Writer, info types.Info) {
463462
if info.OSType == "windows" {
464463
return
465464
}
@@ -470,7 +469,7 @@ func printSecurityOptionsWarnings(dockerCli command.Cli, info types.Info) {
470469
}
471470
for _, o := range so.Options {
472471
if o.Key == "profile" && o.Value != "default" && o.Value != "builtin" {
473-
_, _ = fmt.Fprintln(dockerCli.Err(), "WARNING: You're not using the default seccomp profile")
472+
_, _ = fmt.Fprintln(stdErr, "WARNING: You're not using the default seccomp profile")
474473
}
475474
}
476475
}
@@ -481,39 +480,39 @@ func printSecurityOptionsWarnings(dockerCli command.Cli, info types.Info) {
481480
// info.Warnings. This function is used to provide backward compatibility with
482481
// daemons that do not provide these warnings. No new warnings should be added
483482
// here.
484-
func printServerWarningsLegacy(dockerCli command.Cli, info types.Info) {
483+
func printServerWarningsLegacy(stdErr io.Writer, info types.Info) {
485484
if info.OSType == "windows" {
486485
return
487486
}
488487
if !info.MemoryLimit {
489-
fmt.Fprintln(dockerCli.Err(), "WARNING: No memory limit support")
488+
fmt.Fprintln(stdErr, "WARNING: No memory limit support")
490489
}
491490
if !info.SwapLimit {
492-
fmt.Fprintln(dockerCli.Err(), "WARNING: No swap limit support")
491+
fmt.Fprintln(stdErr, "WARNING: No swap limit support")
493492
}
494493
if !info.OomKillDisable && info.CgroupVersion != "2" {
495-
fmt.Fprintln(dockerCli.Err(), "WARNING: No oom kill disable support")
494+
fmt.Fprintln(stdErr, "WARNING: No oom kill disable support")
496495
}
497496
if !info.CPUCfsQuota {
498-
fmt.Fprintln(dockerCli.Err(), "WARNING: No cpu cfs quota support")
497+
fmt.Fprintln(stdErr, "WARNING: No cpu cfs quota support")
499498
}
500499
if !info.CPUCfsPeriod {
501-
fmt.Fprintln(dockerCli.Err(), "WARNING: No cpu cfs period support")
500+
fmt.Fprintln(stdErr, "WARNING: No cpu cfs period support")
502501
}
503502
if !info.CPUShares {
504-
fmt.Fprintln(dockerCli.Err(), "WARNING: No cpu shares support")
503+
fmt.Fprintln(stdErr, "WARNING: No cpu shares support")
505504
}
506505
if !info.CPUSet {
507-
fmt.Fprintln(dockerCli.Err(), "WARNING: No cpuset support")
506+
fmt.Fprintln(stdErr, "WARNING: No cpuset support")
508507
}
509508
if !info.IPv4Forwarding {
510-
fmt.Fprintln(dockerCli.Err(), "WARNING: IPv4 forwarding is disabled")
509+
fmt.Fprintln(stdErr, "WARNING: IPv4 forwarding is disabled")
511510
}
512511
if !info.BridgeNfIptables {
513-
fmt.Fprintln(dockerCli.Err(), "WARNING: bridge-nf-call-iptables is disabled")
512+
fmt.Fprintln(stdErr, "WARNING: bridge-nf-call-iptables is disabled")
514513
}
515514
if !info.BridgeNfIP6tables {
516-
fmt.Fprintln(dockerCli.Err(), "WARNING: bridge-nf-call-ip6tables is disabled")
515+
fmt.Fprintln(stdErr, "WARNING: bridge-nf-call-ip6tables is disabled")
517516
}
518517
}
519518

0 commit comments

Comments
 (0)