diff --git a/cli/command/system/info.go b/cli/command/system/info.go
index 4bd3e03565..d30f8b2dfb 100644
--- a/cli/command/system/info.go
+++ b/cli/command/system/info.go
@@ -12,7 +12,9 @@ import (
pluginmanager "github.com/docker/cli/cli-plugins/manager"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
+ "github.com/docker/cli/cli/command/formatter"
"github.com/docker/cli/cli/debug"
+ flagsHelper "github.com/docker/cli/cli/flags"
"github.com/docker/cli/templates"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
@@ -62,10 +64,7 @@ func NewInfoCommand(dockerCli command.Cli) *cobra.Command {
ValidArgsFunction: completion.NoComplete,
}
- flags := cmd.Flags()
-
- flags.StringVarP(&opts.format, "format", "f", "", "Format the output using the given Go template")
-
+ cmd.Flags().StringVarP(&opts.format, "format", "f", "", flagsHelper.InspectFormatHelp)
return cmd
}
@@ -507,6 +506,10 @@ func printServerWarningsLegacy(dockerCli command.Cli, info types.Info) {
}
func formatInfo(dockerCli command.Cli, info info, format string) error {
+ if format == formatter.JSONFormatKey {
+ format = formatter.JSONFormat
+ }
+
// Ensure slice/array fields render as `[]` not `null`
if info.ClientInfo != nil && info.ClientInfo.Plugins == nil {
info.ClientInfo.Plugins = make([]pluginmanager.Plugin, 0)
diff --git a/cli/command/system/info_test.go b/cli/command/system/info_test.go
index 199c93721d..5df964006f 100644
--- a/cli/command/system/info_test.go
+++ b/cli/command/system/info_test.go
@@ -396,6 +396,11 @@ func TestPrettyPrintInfo(t *testing.T) {
assert.NilError(t, formatInfo(cli, tc.dockerInfo, "{{json .}}"))
golden.Assert(t, cli.OutBuffer().String(), tc.jsonGolden+".json.golden")
assert.Check(t, is.Equal("", cli.ErrBuffer().String()))
+
+ cli = test.NewFakeCli(&fakeClient{})
+ assert.NilError(t, formatInfo(cli, tc.dockerInfo, "json"))
+ golden.Assert(t, cli.OutBuffer().String(), tc.jsonGolden+".json.golden")
+ assert.Check(t, is.Equal("", cli.ErrBuffer().String()))
}
})
}
diff --git a/docs/reference/commandline/info.md b/docs/reference/commandline/info.md
index 41235357ee..8ba1b821b0 100644
--- a/docs/reference/commandline/info.md
+++ b/docs/reference/commandline/info.md
@@ -9,9 +9,9 @@ Display system-wide information
### Options
-| Name | Type | Default | Description |
-|:---------------------------------------|:---------|:--------|:----------------------------------------------|
-| [`-f`](#format), [`--format`](#format) | `string` | | Format the output using the given Go template |
+| Name | Type | Default | Description |
+|:---------------------------------------|:---------|:--------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| [`-f`](#format), [`--format`](#format) | `string` | | Format output using a custom template:
'json': Print in JSON format
'TEMPLATE': Print output using the given Go template.
Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates |
diff --git a/docs/reference/commandline/system_info.md b/docs/reference/commandline/system_info.md
index 8ef2093a07..e85ace3382 100644
--- a/docs/reference/commandline/system_info.md
+++ b/docs/reference/commandline/system_info.md
@@ -9,9 +9,9 @@ Display system-wide information
### Options
-| Name | Type | Default | Description |
-|:-----------------|:---------|:--------|:----------------------------------------------|
-| `-f`, `--format` | `string` | | Format the output using the given Go template |
+| Name | Type | Default | Description |
+|:-----------------|:---------|:--------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| `-f`, `--format` | `string` | | Format output using a custom template:
'json': Print in JSON format
'TEMPLATE': Print output using the given Go template.
Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates |