Signed-off-by: Victor Vieux <victorvieux@gmail.com>
| ... | ... |
@@ -5,6 +5,7 @@ import ( |
| 5 | 5 |
"fmt" |
| 6 | 6 |
|
| 7 | 7 |
"github.com/docker/docker/api/types" |
| 8 |
+ "github.com/docker/docker/pkg/ioutils" |
|
| 8 | 9 |
flag "github.com/docker/docker/pkg/mflag" |
| 9 | 10 |
"github.com/docker/docker/pkg/units" |
| 10 | 11 |
) |
| ... | ... |
@@ -29,20 +30,20 @@ func (cli *DockerCli) CmdInfo(args ...string) error {
|
| 29 | 29 |
|
| 30 | 30 |
fmt.Fprintf(cli.out, "Containers: %d\n", info.Containers) |
| 31 | 31 |
fmt.Fprintf(cli.out, "Images: %d\n", info.Images) |
| 32 |
- fmt.Fprintf(cli.out, "Storage Driver: %s\n", info.Driver) |
|
| 32 |
+ ioutils.FprintfIfNotEmpty(cli.out, "Storage Driver: %s\n", info.Driver) |
|
| 33 | 33 |
if info.DriverStatus != nil {
|
| 34 | 34 |
for _, pair := range info.DriverStatus {
|
| 35 | 35 |
fmt.Fprintf(cli.out, " %s: %s\n", pair[0], pair[1]) |
| 36 | 36 |
} |
| 37 | 37 |
} |
| 38 |
- fmt.Fprintf(cli.out, "Execution Driver: %s\n", info.ExecutionDriver) |
|
| 39 |
- fmt.Fprintf(cli.out, "Logging Driver: %s\n", info.LoggingDriver) |
|
| 40 |
- fmt.Fprintf(cli.out, "Kernel Version: %s\n", info.KernelVersion) |
|
| 41 |
- fmt.Fprintf(cli.out, "Operating System: %s\n", info.OperatingSystem) |
|
| 38 |
+ ioutils.FprintfIfNotEmpty(cli.out, "Execution Driver: %s\n", info.ExecutionDriver) |
|
| 39 |
+ ioutils.FprintfIfNotEmpty(cli.out, "Logging Driver: %s\n", info.LoggingDriver) |
|
| 40 |
+ ioutils.FprintfIfNotEmpty(cli.out, "Kernel Version: %s\n", info.KernelVersion) |
|
| 41 |
+ ioutils.FprintfIfNotEmpty(cli.out, "Operating System: %s\n", info.OperatingSystem) |
|
| 42 | 42 |
fmt.Fprintf(cli.out, "CPUs: %d\n", info.NCPU) |
| 43 | 43 |
fmt.Fprintf(cli.out, "Total Memory: %s\n", units.BytesSize(float64(info.MemTotal))) |
| 44 |
- fmt.Fprintf(cli.out, "Name: %s\n", info.Name) |
|
| 45 |
- fmt.Fprintf(cli.out, "ID: %s\n", info.ID) |
|
| 44 |
+ ioutils.FprintfIfNotEmpty(cli.out, "Name: %s\n", info.Name) |
|
| 45 |
+ ioutils.FprintfIfNotEmpty(cli.out, "ID: %s\n", info.ID) |
|
| 46 | 46 |
|
| 47 | 47 |
if info.Debug {
|
| 48 | 48 |
fmt.Fprintf(cli.out, "Debug mode (server): %v\n", info.Debug) |
| ... | ... |
@@ -55,15 +56,9 @@ func (cli *DockerCli) CmdInfo(args ...string) error {
|
| 55 | 55 |
fmt.Fprintf(cli.out, "Docker Root Dir: %s\n", info.DockerRootDir) |
| 56 | 56 |
} |
| 57 | 57 |
|
| 58 |
- if info.HttpProxy != "" {
|
|
| 59 |
- fmt.Fprintf(cli.out, "Http Proxy: %s\n", info.HttpProxy) |
|
| 60 |
- } |
|
| 61 |
- if info.HttpsProxy != "" {
|
|
| 62 |
- fmt.Fprintf(cli.out, "Https Proxy: %s\n", info.HttpsProxy) |
|
| 63 |
- } |
|
| 64 |
- if info.NoProxy != "" {
|
|
| 65 |
- fmt.Fprintf(cli.out, "No Proxy: %s\n", info.NoProxy) |
|
| 66 |
- } |
|
| 58 |
+ ioutils.FprintfIfNotEmpty(cli.out, "Http Proxy: %s\n", info.HttpProxy) |
|
| 59 |
+ ioutils.FprintfIfNotEmpty(cli.out, "Https Proxy: %s\n", info.HttpsProxy) |
|
| 60 |
+ ioutils.FprintfIfNotEmpty(cli.out, "No Proxy: %s\n", info.NoProxy) |
|
| 67 | 61 |
|
| 68 | 62 |
if info.IndexServerAddress != "" {
|
| 69 | 63 |
u := cli.configFile.AuthConfigs[info.IndexServerAddress].Username |
| 70 | 64 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,14 @@ |
| 0 |
+package ioutils |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "fmt" |
|
| 4 |
+ "io" |
|
| 5 |
+) |
|
| 6 |
+ |
|
| 7 |
+// FprintfIfNotEmpty prints the string value if it's not empty |
|
| 8 |
+func FprintfIfNotEmpty(w io.Writer, format, value string) (int, error) {
|
|
| 9 |
+ if value != "" {
|
|
| 10 |
+ return fmt.Fprintf(w, format, value) |
|
| 11 |
+ } |
|
| 12 |
+ return 0, nil |
|
| 13 |
+} |
| 0 | 14 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,17 @@ |
| 0 |
+package ioutils |
|
| 1 |
+ |
|
| 2 |
+import "testing" |
|
| 3 |
+ |
|
| 4 |
+func TestFprintfIfNotEmpty(t *testing.T) {
|
|
| 5 |
+ wc := NewWriteCounter(&NopWriter{})
|
|
| 6 |
+ n, _ := FprintfIfNotEmpty(wc, "foo%s", "") |
|
| 7 |
+ |
|
| 8 |
+ if wc.Count != 0 || n != 0 {
|
|
| 9 |
+ t.Errorf("Wrong count: %v vs. %v vs. 0", wc.Count, n)
|
|
| 10 |
+ } |
|
| 11 |
+ |
|
| 12 |
+ n, _ = FprintfIfNotEmpty(wc, "foo%s", "bar") |
|
| 13 |
+ if wc.Count != 6 || n != 6 {
|
|
| 14 |
+ t.Errorf("Wrong count: %v vs. %v vs. 6", wc.Count, n)
|
|
| 15 |
+ } |
|
| 16 |
+} |