From a4a734df448d91885b87858e4c14bb2b313f554a Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Wed, 10 Mar 2021 00:45:56 +0100 Subject: [PATCH] Update list commands with better format flag description including all the directives and a link to the documentation. Signed-off-by: Silvin Lubecki Signed-off-by: Sebastiaan van Stijn --- cli/command/config/ls.go | 3 ++- cli/command/container/list.go | 4 ++-- cli/command/container/stats.go | 3 ++- cli/command/context/list.go | 3 ++- cli/command/image/history.go | 3 ++- cli/command/image/list.go | 3 ++- cli/command/network/list.go | 3 ++- cli/command/node/list.go | 3 ++- cli/command/plugin/list.go | 3 ++- cli/command/secret/ls.go | 3 ++- cli/command/service/list.go | 3 ++- cli/command/stack/list.go | 3 ++- cli/command/stack/ps.go | 3 ++- cli/command/stack/services.go | 3 ++- cli/command/system/df.go | 3 ++- cli/command/volume/list.go | 3 ++- cli/flags/common.go | 7 +++++++ 17 files changed, 39 insertions(+), 17 deletions(-) diff --git a/cli/command/config/ls.go b/cli/command/config/ls.go index 57bb13320b..af463adbc6 100644 --- a/cli/command/config/ls.go +++ b/cli/command/config/ls.go @@ -7,6 +7,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/formatter" + flagsHelper "github.com/docker/cli/cli/flags" "github.com/docker/cli/opts" "github.com/docker/docker/api/types" "github.com/fvbommel/sortorder" @@ -35,7 +36,7 @@ func newConfigListCommand(dockerCli command.Cli) *cobra.Command { flags := cmd.Flags() flags.BoolVarP(&listOpts.Quiet, "quiet", "q", false, "Only display IDs") - flags.StringVarP(&listOpts.Format, "format", "", "", "Pretty-print configs using a Go template") + flags.StringVarP(&listOpts.Format, "format", "", "", flagsHelper.FormatHelp) flags.VarP(&listOpts.Filter, "filter", "f", "Filter output based on conditions provided") return cmd diff --git a/cli/command/container/list.go b/cli/command/container/list.go index b9146506c6..99b5c7ef27 100644 --- a/cli/command/container/list.go +++ b/cli/command/container/list.go @@ -7,6 +7,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/formatter" + flagsHelper "github.com/docker/cli/cli/flags" "github.com/docker/cli/opts" "github.com/docker/cli/templates" "github.com/docker/docker/api/types" @@ -46,7 +47,7 @@ func NewPsCommand(dockerCli command.Cli) *cobra.Command { flags.BoolVar(&options.noTrunc, "no-trunc", false, "Don't truncate output") flags.BoolVarP(&options.nLatest, "latest", "l", false, "Show the latest created container (includes all states)") flags.IntVarP(&options.last, "last", "n", -1, "Show n last created containers (includes all states)") - flags.StringVarP(&options.format, "format", "", "", "Pretty-print containers using a Go template") + flags.StringVarP(&options.format, "format", "", "", flagsHelper.FormatHelp) flags.VarP(&options.filter, "filter", "f", "Filter output based on conditions provided") return cmd @@ -80,7 +81,6 @@ func buildContainerListOptions(opts *psOptions) (*types.ContainerListOptions, er // Only requesting container size information when needed is an optimization, // because calculating the size is a costly operation. tmpl, err := templates.NewParse("", opts.format) - if err != nil { return nil, errors.Wrap(err, "failed to parse template") } diff --git a/cli/command/container/stats.go b/cli/command/container/stats.go index c6a193cf12..287fe02f7c 100644 --- a/cli/command/container/stats.go +++ b/cli/command/container/stats.go @@ -11,6 +11,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/formatter" + flagsHelper "github.com/docker/cli/cli/flags" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/events" "github.com/docker/docker/api/types/filters" @@ -44,7 +45,7 @@ func NewStatsCommand(dockerCli command.Cli) *cobra.Command { flags.BoolVarP(&opts.all, "all", "a", false, "Show all containers (default shows just running)") flags.BoolVar(&opts.noStream, "no-stream", false, "Disable streaming stats and only pull the first result") flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Do not truncate output") - flags.StringVar(&opts.format, "format", "", "Pretty-print images using a Go template") + flags.StringVar(&opts.format, "format", "", flagsHelper.FormatHelp) return cmd } diff --git a/cli/command/context/list.go b/cli/command/context/list.go index 3bffcd4d0f..8e8a71950f 100644 --- a/cli/command/context/list.go +++ b/cli/command/context/list.go @@ -9,6 +9,7 @@ import ( "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/formatter" "github.com/docker/cli/cli/context/docker" + flagsHelper "github.com/docker/cli/cli/flags" "github.com/fvbommel/sortorder" "github.com/spf13/cobra" ) @@ -31,7 +32,7 @@ func newListCommand(dockerCli command.Cli) *cobra.Command { } flags := cmd.Flags() - flags.StringVar(&opts.format, "format", "", "Pretty-print contexts using a Go template") + flags.StringVar(&opts.format, "format", "", flagsHelper.FormatHelp) flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only show context names") return cmd } diff --git a/cli/command/image/history.go b/cli/command/image/history.go index d1bff9de20..fd98ee1399 100644 --- a/cli/command/image/history.go +++ b/cli/command/image/history.go @@ -6,6 +6,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/formatter" + flagsHelper "github.com/docker/cli/cli/flags" "github.com/spf13/cobra" ) @@ -37,7 +38,7 @@ func NewHistoryCommand(dockerCli command.Cli) *cobra.Command { flags.BoolVarP(&opts.human, "human", "H", true, "Print sizes and dates in human readable format") flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only show image IDs") flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Don't truncate output") - flags.StringVar(&opts.format, "format", "", "Pretty-print images using a Go template") + flags.StringVar(&opts.format, "format", "", flagsHelper.FormatHelp) return cmd } diff --git a/cli/command/image/list.go b/cli/command/image/list.go index f60129d17a..7f1a8df3a7 100644 --- a/cli/command/image/list.go +++ b/cli/command/image/list.go @@ -6,6 +6,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/formatter" + flagsHelper "github.com/docker/cli/cli/flags" "github.com/docker/cli/opts" "github.com/docker/docker/api/types" "github.com/spf13/cobra" @@ -44,7 +45,7 @@ func NewImagesCommand(dockerCli command.Cli) *cobra.Command { flags.BoolVarP(&options.all, "all", "a", false, "Show all images (default hides intermediate images)") flags.BoolVar(&options.noTrunc, "no-trunc", false, "Don't truncate output") flags.BoolVar(&options.showDigests, "digests", false, "Show digests") - flags.StringVar(&options.format, "format", "", "Pretty-print images using a Go template") + flags.StringVar(&options.format, "format", "", flagsHelper.FormatHelp) flags.VarP(&options.filter, "filter", "f", "Filter output based on conditions provided") return cmd diff --git a/cli/command/network/list.go b/cli/command/network/list.go index e72703b212..fa6abcb3e8 100644 --- a/cli/command/network/list.go +++ b/cli/command/network/list.go @@ -7,6 +7,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/formatter" + flagsHelper "github.com/docker/cli/cli/flags" "github.com/docker/cli/opts" "github.com/docker/docker/api/types" "github.com/fvbommel/sortorder" @@ -36,7 +37,7 @@ func newListCommand(dockerCli command.Cli) *cobra.Command { flags := cmd.Flags() flags.BoolVarP(&options.quiet, "quiet", "q", false, "Only display network IDs") flags.BoolVar(&options.noTrunc, "no-trunc", false, "Do not truncate the output") - flags.StringVar(&options.format, "format", "", "Pretty-print networks using a Go template") + flags.StringVar(&options.format, "format", "", flagsHelper.FormatHelp) flags.VarP(&options.filter, "filter", "f", "Provide filter values (e.g. 'driver=bridge')") return cmd diff --git a/cli/command/node/list.go b/cli/command/node/list.go index d67f54a042..6fee9a9b11 100644 --- a/cli/command/node/list.go +++ b/cli/command/node/list.go @@ -7,6 +7,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/formatter" + flagsHelper "github.com/docker/cli/cli/flags" "github.com/docker/cli/opts" "github.com/docker/docker/api/types" "github.com/fvbommel/sortorder" @@ -33,7 +34,7 @@ func newListCommand(dockerCli command.Cli) *cobra.Command { } flags := cmd.Flags() flags.BoolVarP(&options.quiet, "quiet", "q", false, "Only display IDs") - flags.StringVar(&options.format, "format", "", "Pretty-print nodes using a Go template") + flags.StringVar(&options.format, "format", "", flagsHelper.FormatHelp) flags.VarP(&options.filter, "filter", "f", "Filter output based on conditions provided") return cmd diff --git a/cli/command/plugin/list.go b/cli/command/plugin/list.go index c05eefae79..0a37fb6538 100644 --- a/cli/command/plugin/list.go +++ b/cli/command/plugin/list.go @@ -7,6 +7,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/formatter" + flagsHelper "github.com/docker/cli/cli/flags" "github.com/docker/cli/opts" "github.com/fvbommel/sortorder" "github.com/spf13/cobra" @@ -36,7 +37,7 @@ func newListCommand(dockerCli command.Cli) *cobra.Command { flags.BoolVarP(&options.quiet, "quiet", "q", false, "Only display plugin IDs") flags.BoolVar(&options.noTrunc, "no-trunc", false, "Don't truncate output") - flags.StringVar(&options.format, "format", "", "Pretty-print plugins using a Go template") + flags.StringVar(&options.format, "format", "", flagsHelper.FormatHelp) flags.VarP(&options.filter, "filter", "f", "Provide filter values (e.g. 'enabled=true')") return cmd diff --git a/cli/command/secret/ls.go b/cli/command/secret/ls.go index 5d1d54150a..c1f11f88d4 100644 --- a/cli/command/secret/ls.go +++ b/cli/command/secret/ls.go @@ -7,6 +7,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/formatter" + flagsHelper "github.com/docker/cli/cli/flags" "github.com/docker/cli/opts" "github.com/docker/docker/api/types" "github.com/fvbommel/sortorder" @@ -34,7 +35,7 @@ func newSecretListCommand(dockerCli command.Cli) *cobra.Command { flags := cmd.Flags() flags.BoolVarP(&options.quiet, "quiet", "q", false, "Only display IDs") - flags.StringVarP(&options.format, "format", "", "", "Pretty-print secrets using a Go template") + flags.StringVarP(&options.format, "format", "", "", flagsHelper.FormatHelp) flags.VarP(&options.filter, "filter", "f", "Filter output based on conditions provided") return cmd diff --git a/cli/command/service/list.go b/cli/command/service/list.go index 56cb3a23ba..842205a579 100644 --- a/cli/command/service/list.go +++ b/cli/command/service/list.go @@ -6,6 +6,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/formatter" + flagsHelper "github.com/docker/cli/cli/flags" "github.com/docker/cli/opts" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" @@ -35,7 +36,7 @@ func newListCommand(dockerCli command.Cli) *cobra.Command { flags := cmd.Flags() flags.BoolVarP(&options.quiet, "quiet", "q", false, "Only display IDs") - flags.StringVar(&options.format, "format", "", "Pretty-print services using a Go template") + flags.StringVar(&options.format, "format", "", flagsHelper.FormatHelp) flags.VarP(&options.filter, "filter", "f", "Filter output based on conditions provided") return cmd diff --git a/cli/command/stack/list.go b/cli/command/stack/list.go index 17f2e7947b..866961b2e5 100644 --- a/cli/command/stack/list.go +++ b/cli/command/stack/list.go @@ -8,6 +8,7 @@ import ( "github.com/docker/cli/cli/command/stack/formatter" "github.com/docker/cli/cli/command/stack/options" "github.com/docker/cli/cli/command/stack/swarm" + flagsHelper "github.com/docker/cli/cli/flags" "github.com/fvbommel/sortorder" "github.com/spf13/cobra" ) @@ -26,7 +27,7 @@ func newListCommand(dockerCli command.Cli) *cobra.Command { } flags := cmd.Flags() - flags.StringVar(&opts.Format, "format", "", "Pretty-print stacks using a Go template") + flags.StringVar(&opts.Format, "format", "", flagsHelper.FormatHelp) return cmd } diff --git a/cli/command/stack/ps.go b/cli/command/stack/ps.go index 3dd8f82cc6..cbe992cfa5 100644 --- a/cli/command/stack/ps.go +++ b/cli/command/stack/ps.go @@ -5,6 +5,7 @@ import ( "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/stack/options" "github.com/docker/cli/cli/command/stack/swarm" + flagsHelper "github.com/docker/cli/cli/flags" cliopts "github.com/docker/cli/opts" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -30,7 +31,7 @@ func newPsCommand(dockerCli command.Cli) *cobra.Command { flags.BoolVar(&opts.NoResolve, "no-resolve", false, "Do not map IDs to Names") flags.VarP(&opts.Filter, "filter", "f", "Filter output based on conditions provided") flags.BoolVarP(&opts.Quiet, "quiet", "q", false, "Only display task IDs") - flags.StringVar(&opts.Format, "format", "", "Pretty-print tasks using a Go template") + flags.StringVar(&opts.Format, "format", "", flagsHelper.FormatHelp) return cmd } diff --git a/cli/command/stack/services.go b/cli/command/stack/services.go index c955af2785..456a1fad04 100644 --- a/cli/command/stack/services.go +++ b/cli/command/stack/services.go @@ -10,6 +10,7 @@ import ( "github.com/docker/cli/cli/command/stack/formatter" "github.com/docker/cli/cli/command/stack/options" "github.com/docker/cli/cli/command/stack/swarm" + flagsHelper "github.com/docker/cli/cli/flags" cliopts "github.com/docker/cli/opts" swarmtypes "github.com/docker/docker/api/types/swarm" "github.com/fvbommel/sortorder" @@ -34,7 +35,7 @@ func newServicesCommand(dockerCli command.Cli) *cobra.Command { } flags := cmd.Flags() flags.BoolVarP(&opts.Quiet, "quiet", "q", false, "Only display IDs") - flags.StringVar(&opts.Format, "format", "", "Pretty-print services using a Go template") + flags.StringVar(&opts.Format, "format", "", flagsHelper.FormatHelp) flags.VarP(&opts.Filter, "filter", "f", "Filter output based on conditions provided") return cmd } diff --git a/cli/command/system/df.go b/cli/command/system/df.go index ba91c9d1be..bb1bf2cf43 100644 --- a/cli/command/system/df.go +++ b/cli/command/system/df.go @@ -6,6 +6,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/formatter" + flagsHelper "github.com/docker/cli/cli/flags" "github.com/docker/docker/api/types" "github.com/spf13/cobra" ) @@ -32,7 +33,7 @@ func newDiskUsageCommand(dockerCli command.Cli) *cobra.Command { flags := cmd.Flags() flags.BoolVarP(&opts.verbose, "verbose", "v", false, "Show detailed information on space usage") - flags.StringVar(&opts.format, "format", "", "Pretty-print images using a Go template") + flags.StringVar(&opts.format, "format", "", flagsHelper.FormatHelp) return cmd } diff --git a/cli/command/volume/list.go b/cli/command/volume/list.go index 4793e72d51..7b5a27ac8e 100644 --- a/cli/command/volume/list.go +++ b/cli/command/volume/list.go @@ -7,6 +7,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/formatter" + flagsHelper "github.com/docker/cli/cli/flags" "github.com/docker/cli/opts" "github.com/fvbommel/sortorder" "github.com/spf13/cobra" @@ -33,7 +34,7 @@ func newListCommand(dockerCli command.Cli) *cobra.Command { flags := cmd.Flags() flags.BoolVarP(&options.quiet, "quiet", "q", false, "Only display volume names") - flags.StringVar(&options.format, "format", "", "Pretty-print volumes using a Go template") + flags.StringVar(&options.format, "format", "", flagsHelper.FormatHelp) flags.VarP(&options.filter, "filter", "f", "Provide filter values (e.g. 'dangling=true')") return cmd diff --git a/cli/flags/common.go b/cli/flags/common.go index f692af75f7..a770333a49 100644 --- a/cli/flags/common.go +++ b/cli/flags/common.go @@ -21,6 +21,13 @@ const ( DefaultCertFile = "cert.pem" // FlagTLSVerify is the flag name for the TLS verification option FlagTLSVerify = "tlsverify" + // FormatHelp describes the --format flag behavior for list commands + FormatHelp = `Format output using a custom template: +'table': Print output in table format with column headers (default) +'table TEMPLATE': Print output in table format using the given Go 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` // InspectFormatHelp describes the --format flag behavior for inspect commands InspectFormatHelp = `Format output using a custom template: 'json': Print in JSON format