mirror of https://github.com/docker/cli.git
Update code for upstream cobra
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
0f2ebae056
commit
4205416c9b
|
@ -13,7 +13,7 @@ func NewCheckpointCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
Short: "Manage checkpoints",
|
Short: "Manage checkpoints",
|
||||||
Args: cli.NoArgs,
|
Args: cli.NoArgs,
|
||||||
RunE: command.ShowHelp(dockerCli.Err()),
|
RunE: command.ShowHelp(dockerCli.Err()),
|
||||||
Tags: map[string]string{"experimental": "", "version": "1.25"},
|
Annotations: map[string]string{"experimental": "", "version": "1.25"},
|
||||||
}
|
}
|
||||||
cmd.AddCommand(
|
cmd.AddCommand(
|
||||||
newCreateCommand(dockerCli),
|
newCreateCommand(dockerCli),
|
||||||
|
|
|
@ -15,7 +15,7 @@ func NewConfigCommand(dockerCli *command.DockerCli) *cobra.Command {
|
||||||
Short: "Manage Docker configs",
|
Short: "Manage Docker configs",
|
||||||
Args: cli.NoArgs,
|
Args: cli.NoArgs,
|
||||||
RunE: command.ShowHelp(dockerCli.Err()),
|
RunE: command.ShowHelp(dockerCli.Err()),
|
||||||
Tags: map[string]string{"version": "1.30"},
|
Annotations: map[string]string{"version": "1.30"},
|
||||||
}
|
}
|
||||||
cmd.AddCommand(
|
cmd.AddCommand(
|
||||||
newConfigListCommand(dockerCli),
|
newConfigListCommand(dockerCli),
|
||||||
|
|
|
@ -45,10 +45,7 @@ func TestValidateAttach(t *testing.T) {
|
||||||
|
|
||||||
// nolint: unparam
|
// nolint: unparam
|
||||||
func parseRun(args []string) (*container.Config, *container.HostConfig, *networktypes.NetworkingConfig, error) {
|
func parseRun(args []string) (*container.Config, *container.HostConfig, *networktypes.NetworkingConfig, error) {
|
||||||
flags := pflag.NewFlagSet("run", pflag.ContinueOnError)
|
flags, copts := setupRunFlags()
|
||||||
flags.SetOutput(ioutil.Discard)
|
|
||||||
flags.Usage = nil
|
|
||||||
copts := addFlags(flags)
|
|
||||||
if err := flags.Parse(args); err != nil {
|
if err := flags.Parse(args); err != nil {
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
|
@ -60,6 +57,14 @@ func parseRun(args []string) (*container.Config, *container.HostConfig, *network
|
||||||
return containerConfig.Config, containerConfig.HostConfig, containerConfig.NetworkingConfig, err
|
return containerConfig.Config, containerConfig.HostConfig, containerConfig.NetworkingConfig, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setupRunFlags() (*pflag.FlagSet, *containerOptions) {
|
||||||
|
flags := pflag.NewFlagSet("run", pflag.ContinueOnError)
|
||||||
|
flags.SetOutput(ioutil.Discard)
|
||||||
|
flags.Usage = nil
|
||||||
|
copts := addFlags(flags)
|
||||||
|
return flags, copts
|
||||||
|
}
|
||||||
|
|
||||||
func parseMustError(t *testing.T, args string) {
|
func parseMustError(t *testing.T, args string) {
|
||||||
_, _, _, err := parseRun(strings.Split(args+" ubuntu bash", " "))
|
_, _, _, err := parseRun(strings.Split(args+" ubuntu bash", " "))
|
||||||
assert.Error(t, err, args)
|
assert.Error(t, err, args)
|
||||||
|
@ -227,20 +232,21 @@ func TestParseWithMacAddress(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseWithMemory(t *testing.T) {
|
func TestRunFlagsParseWithMemory(t *testing.T) {
|
||||||
invalidMemory := "--memory=invalid"
|
flags, _ := setupRunFlags()
|
||||||
_, _, _, err := parseRun([]string{invalidMemory, "img", "cmd"})
|
args := []string{"--memory=invalid", "img", "cmd"}
|
||||||
testutil.ErrorContains(t, err, invalidMemory)
|
err := flags.Parse(args)
|
||||||
|
testutil.ErrorContains(t, err, `invalid argument "invalid" for "-m, --memory" flag`)
|
||||||
|
|
||||||
_, hostconfig := mustParse(t, "--memory=1G")
|
_, hostconfig := mustParse(t, "--memory=1G")
|
||||||
assert.Equal(t, int64(1073741824), hostconfig.Memory)
|
assert.Equal(t, int64(1073741824), hostconfig.Memory)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseWithMemorySwap(t *testing.T) {
|
func TestParseWithMemorySwap(t *testing.T) {
|
||||||
invalidMemory := "--memory-swap=invalid"
|
flags, _ := setupRunFlags()
|
||||||
|
args := []string{"--memory-swap=invalid", "img", "cmd"}
|
||||||
_, _, _, err := parseRun([]string{invalidMemory, "img", "cmd"})
|
err := flags.Parse(args)
|
||||||
testutil.ErrorContains(t, err, invalidMemory)
|
testutil.ErrorContains(t, err, `invalid argument "invalid" for "--memory-swap" flag`)
|
||||||
|
|
||||||
_, hostconfig := mustParse(t, "--memory-swap=1G")
|
_, hostconfig := mustParse(t, "--memory-swap=1G")
|
||||||
assert.Equal(t, int64(1073741824), hostconfig.MemorySwap)
|
assert.Equal(t, int64(1073741824), hostconfig.MemorySwap)
|
||||||
|
@ -365,7 +371,10 @@ func TestParseDevice(t *testing.T) {
|
||||||
|
|
||||||
func TestParseModes(t *testing.T) {
|
func TestParseModes(t *testing.T) {
|
||||||
// pid ko
|
// pid ko
|
||||||
_, _, _, err := parseRun([]string{"--pid=container:", "img", "cmd"})
|
flags, copts := setupRunFlags()
|
||||||
|
args := []string{"--pid=container:", "img", "cmd"}
|
||||||
|
require.NoError(t, flags.Parse(args))
|
||||||
|
_, err := parse(flags, copts)
|
||||||
testutil.ErrorContains(t, err, "--pid: invalid PID mode")
|
testutil.ErrorContains(t, err, "--pid: invalid PID mode")
|
||||||
|
|
||||||
// pid ok
|
// pid ok
|
||||||
|
@ -385,14 +394,18 @@ func TestParseModes(t *testing.T) {
|
||||||
if !hostconfig.UTSMode.Valid() {
|
if !hostconfig.UTSMode.Valid() {
|
||||||
t.Fatalf("Expected a valid UTSMode, got %v", hostconfig.UTSMode)
|
t.Fatalf("Expected a valid UTSMode, got %v", hostconfig.UTSMode)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRunFlagsParseShmSize(t *testing.T) {
|
||||||
// shm-size ko
|
// shm-size ko
|
||||||
expectedErr := `invalid argument "a128m" for --shm-size=a128m: invalid size: 'a128m'`
|
flags, _ := setupRunFlags()
|
||||||
_, _, _, err = parseRun([]string{"--shm-size=a128m", "img", "cmd"})
|
args := []string{"--shm-size=a128m", "img", "cmd"}
|
||||||
|
expectedErr := `invalid argument "a128m" for "--shm-size" flag: invalid size: 'a128m'`
|
||||||
|
err := flags.Parse(args)
|
||||||
testutil.ErrorContains(t, err, expectedErr)
|
testutil.ErrorContains(t, err, expectedErr)
|
||||||
|
|
||||||
// shm-size ok
|
// shm-size ok
|
||||||
_, hostconfig, _, err = parseRun([]string{"--shm-size=128m", "img", "cmd"})
|
_, hostconfig, _, err := parseRun([]string{"--shm-size=128m", "img", "cmd"})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
if hostconfig.ShmSize != 134217728 {
|
if hostconfig.ShmSize != 134217728 {
|
||||||
t.Fatalf("Expected a valid ShmSize, got %d", hostconfig.ShmSize)
|
t.Fatalf("Expected a valid ShmSize, got %d", hostconfig.ShmSize)
|
||||||
|
|
|
@ -35,7 +35,7 @@ func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed)))
|
fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed)))
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
Tags: map[string]string{"version": "1.25"},
|
Annotations: map[string]string{"version": "1.25"},
|
||||||
}
|
}
|
||||||
|
|
||||||
flags := cmd.Flags()
|
flags := cmd.Flags()
|
||||||
|
|
|
@ -37,7 +37,7 @@ func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed)))
|
fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed)))
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
Tags: map[string]string{"version": "1.25"},
|
Annotations: map[string]string{"version": "1.25"},
|
||||||
}
|
}
|
||||||
|
|
||||||
flags := cmd.Flags()
|
flags := cmd.Flags()
|
||||||
|
|
|
@ -33,7 +33,7 @@ func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
Tags: map[string]string{"version": "1.25"},
|
Annotations: map[string]string{"version": "1.25"},
|
||||||
}
|
}
|
||||||
|
|
||||||
flags := cmd.Flags()
|
flags := cmd.Flags()
|
||||||
|
|
|
@ -18,7 +18,7 @@ func NewNodeCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
Short: "Manage Swarm nodes",
|
Short: "Manage Swarm nodes",
|
||||||
Args: cli.NoArgs,
|
Args: cli.NoArgs,
|
||||||
RunE: command.ShowHelp(dockerCli.Err()),
|
RunE: command.ShowHelp(dockerCli.Err()),
|
||||||
Tags: map[string]string{"version": "1.24"},
|
Annotations: map[string]string{"version": "1.24"},
|
||||||
}
|
}
|
||||||
cmd.AddCommand(
|
cmd.AddCommand(
|
||||||
newDemoteCommand(dockerCli),
|
newDemoteCommand(dockerCli),
|
||||||
|
|
|
@ -14,7 +14,7 @@ func NewPluginCommand(dockerCli *command.DockerCli) *cobra.Command {
|
||||||
Short: "Manage plugins",
|
Short: "Manage plugins",
|
||||||
Args: cli.NoArgs,
|
Args: cli.NoArgs,
|
||||||
RunE: command.ShowHelp(dockerCli.Err()),
|
RunE: command.ShowHelp(dockerCli.Err()),
|
||||||
Tags: map[string]string{"version": "1.25"},
|
Annotations: map[string]string{"version": "1.25"},
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.AddCommand(
|
cmd.AddCommand(
|
||||||
|
|
|
@ -26,7 +26,7 @@ func newUpgradeCommand(dockerCli *command.DockerCli) *cobra.Command {
|
||||||
}
|
}
|
||||||
return runUpgrade(dockerCli, options)
|
return runUpgrade(dockerCli, options)
|
||||||
},
|
},
|
||||||
Tags: map[string]string{"version": "1.26"},
|
Annotations: map[string]string{"version": "1.26"},
|
||||||
}
|
}
|
||||||
|
|
||||||
flags := cmd.Flags()
|
flags := cmd.Flags()
|
||||||
|
|
|
@ -15,7 +15,7 @@ func NewSecretCommand(dockerCli *command.DockerCli) *cobra.Command {
|
||||||
Short: "Manage Docker secrets",
|
Short: "Manage Docker secrets",
|
||||||
Args: cli.NoArgs,
|
Args: cli.NoArgs,
|
||||||
RunE: command.ShowHelp(dockerCli.Err()),
|
RunE: command.ShowHelp(dockerCli.Err()),
|
||||||
Tags: map[string]string{"version": "1.25"},
|
Annotations: map[string]string{"version": "1.25"},
|
||||||
}
|
}
|
||||||
cmd.AddCommand(
|
cmd.AddCommand(
|
||||||
newSecretListCommand(dockerCli),
|
newSecretListCommand(dockerCli),
|
||||||
|
|
|
@ -15,7 +15,7 @@ func NewServiceCommand(dockerCli *command.DockerCli) *cobra.Command {
|
||||||
Short: "Manage services",
|
Short: "Manage services",
|
||||||
Args: cli.NoArgs,
|
Args: cli.NoArgs,
|
||||||
RunE: command.ShowHelp(dockerCli.Err()),
|
RunE: command.ShowHelp(dockerCli.Err()),
|
||||||
Tags: map[string]string{"version": "1.24"},
|
Annotations: map[string]string{"version": "1.24"},
|
||||||
}
|
}
|
||||||
cmd.AddCommand(
|
cmd.AddCommand(
|
||||||
newCreateCommand(dockerCli),
|
newCreateCommand(dockerCli),
|
||||||
|
|
|
@ -48,7 +48,7 @@ func newLogsCommand(dockerCli *command.DockerCli) *cobra.Command {
|
||||||
opts.target = args[0]
|
opts.target = args[0]
|
||||||
return runLogs(dockerCli, &opts)
|
return runLogs(dockerCli, &opts)
|
||||||
},
|
},
|
||||||
Tags: map[string]string{"version": "1.29"},
|
Annotations: map[string]string{"version": "1.29"},
|
||||||
}
|
}
|
||||||
|
|
||||||
flags := cmd.Flags()
|
flags := cmd.Flags()
|
||||||
|
|
|
@ -21,7 +21,7 @@ func newRollbackCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
return runRollback(dockerCli, options, args[0])
|
return runRollback(dockerCli, options, args[0])
|
||||||
},
|
},
|
||||||
Tags: map[string]string{"version": "1.31"},
|
Annotations: map[string]string{"version": "1.31"},
|
||||||
}
|
}
|
||||||
|
|
||||||
flags := cmd.Flags()
|
flags := cmd.Flags()
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/docker/cli/internal/test/testutil"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
mounttypes "github.com/docker/docker/api/types/mount"
|
mounttypes "github.com/docker/docker/api/types/mount"
|
||||||
|
@ -165,7 +166,7 @@ func TestUpdateDNSConfig(t *testing.T) {
|
||||||
// IPv6
|
// IPv6
|
||||||
flags.Set("dns-add", "2001:db8:abc8::1")
|
flags.Set("dns-add", "2001:db8:abc8::1")
|
||||||
// Invalid dns record
|
// Invalid dns record
|
||||||
assert.EqualError(t, flags.Set("dns-add", "x.y.z.w"), "x.y.z.w is not an ip address")
|
testutil.ErrorContains(t, flags.Set("dns-add", "x.y.z.w"), "x.y.z.w is not an ip address")
|
||||||
|
|
||||||
// domains with duplicates
|
// domains with duplicates
|
||||||
flags.Set("dns-search-add", "example.com")
|
flags.Set("dns-search-add", "example.com")
|
||||||
|
@ -173,7 +174,7 @@ func TestUpdateDNSConfig(t *testing.T) {
|
||||||
flags.Set("dns-search-add", "example.org")
|
flags.Set("dns-search-add", "example.org")
|
||||||
flags.Set("dns-search-rm", "example.org")
|
flags.Set("dns-search-rm", "example.org")
|
||||||
// Invalid dns search domain
|
// Invalid dns search domain
|
||||||
assert.EqualError(t, flags.Set("dns-search-add", "example$com"), "example$com is not a valid domain")
|
testutil.ErrorContains(t, flags.Set("dns-search-add", "example$com"), "example$com is not a valid domain")
|
||||||
|
|
||||||
flags.Set("dns-option-add", "ndots:9")
|
flags.Set("dns-option-add", "ndots:9")
|
||||||
flags.Set("dns-option-rm", "timeout:3")
|
flags.Set("dns-option-rm", "timeout:3")
|
||||||
|
@ -362,7 +363,7 @@ func TestUpdateHosts(t *testing.T) {
|
||||||
// just hostname should work as well
|
// just hostname should work as well
|
||||||
flags.Set("host-rm", "example.net")
|
flags.Set("host-rm", "example.net")
|
||||||
// bad format error
|
// bad format error
|
||||||
assert.EqualError(t, flags.Set("host-add", "$example.com$"), `bad format for add-host: "$example.com$"`)
|
testutil.ErrorContains(t, flags.Set("host-add", "$example.com$"), `bad format for add-host: "$example.com$"`)
|
||||||
|
|
||||||
hosts := []string{"1.2.3.4 example.com", "4.3.2.1 example.org", "2001:db8:abc8::1 example.net"}
|
hosts := []string{"1.2.3.4 example.com", "4.3.2.1 example.org", "2001:db8:abc8::1 example.net"}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ func NewStackCommand(dockerCli *command.DockerCli) *cobra.Command {
|
||||||
Short: "Manage Docker stacks",
|
Short: "Manage Docker stacks",
|
||||||
Args: cli.NoArgs,
|
Args: cli.NoArgs,
|
||||||
RunE: command.ShowHelp(dockerCli.Err()),
|
RunE: command.ShowHelp(dockerCli.Err()),
|
||||||
Tags: map[string]string{"version": "1.25"},
|
Annotations: map[string]string{"version": "1.25"},
|
||||||
}
|
}
|
||||||
cmd.AddCommand(
|
cmd.AddCommand(
|
||||||
newDeployCommand(dockerCli),
|
newDeployCommand(dockerCli),
|
||||||
|
@ -31,6 +31,6 @@ func NewTopLevelDeployCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
cmd := newDeployCommand(dockerCli)
|
cmd := newDeployCommand(dockerCli)
|
||||||
// Remove the aliases at the top level
|
// Remove the aliases at the top level
|
||||||
cmd.Aliases = []string{}
|
cmd.Aliases = []string{}
|
||||||
cmd.Tags = map[string]string{"experimental": "", "version": "1.25"}
|
cmd.Annotations = map[string]string{"experimental": "", "version": "1.25"}
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ func newCACommand(dockerCli command.Cli) *cobra.Command {
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
return runCA(dockerCli, cmd.Flags(), opts)
|
return runCA(dockerCli, cmd.Flags(), opts)
|
||||||
},
|
},
|
||||||
Tags: map[string]string{"version": "1.30"},
|
Annotations: map[string]string{"version": "1.30"},
|
||||||
}
|
}
|
||||||
|
|
||||||
flags := cmd.Flags()
|
flags := cmd.Flags()
|
||||||
|
|
|
@ -15,7 +15,7 @@ func NewSwarmCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
Short: "Manage Swarm",
|
Short: "Manage Swarm",
|
||||||
Args: cli.NoArgs,
|
Args: cli.NoArgs,
|
||||||
RunE: command.ShowHelp(dockerCli.Err()),
|
RunE: command.ShowHelp(dockerCli.Err()),
|
||||||
Tags: map[string]string{"version": "1.24"},
|
Annotations: map[string]string{"version": "1.24"},
|
||||||
}
|
}
|
||||||
cmd.AddCommand(
|
cmd.AddCommand(
|
||||||
newInitCommand(dockerCli),
|
newInitCommand(dockerCli),
|
||||||
|
|
|
@ -8,6 +8,7 @@ Flags:
|
||||||
--cert-expiry duration Validity period for node certificates (ns|us|ms|s|m|h) (default 2160h0m0s)
|
--cert-expiry duration Validity period for node certificates (ns|us|ms|s|m|h) (default 2160h0m0s)
|
||||||
--dispatcher-heartbeat duration Dispatcher heartbeat period (ns|us|ms|s|m|h) (default 5s)
|
--dispatcher-heartbeat duration Dispatcher heartbeat period (ns|us|ms|s|m|h) (default 5s)
|
||||||
--external-ca external-ca Specifications of one or more certificate signing endpoints
|
--external-ca external-ca Specifications of one or more certificate signing endpoints
|
||||||
|
-h, --help help for update
|
||||||
--max-snapshots uint Number of additional Raft snapshots to retain
|
--max-snapshots uint Number of additional Raft snapshots to retain
|
||||||
--snapshot-interval uint Number of log entries between Raft snapshots (default 10000)
|
--snapshot-interval uint Number of log entries between Raft snapshots (default 10000)
|
||||||
--task-history-limit int Task history retention limit (default 5)
|
--task-history-limit int Task history retention limit (default 5)
|
||||||
|
|
|
@ -26,7 +26,7 @@ func newDiskUsageCommand(dockerCli *command.DockerCli) *cobra.Command {
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
return runDiskUsage(dockerCli, opts)
|
return runDiskUsage(dockerCli, opts)
|
||||||
},
|
},
|
||||||
Tags: map[string]string{"version": "1.25"},
|
Annotations: map[string]string{"version": "1.25"},
|
||||||
}
|
}
|
||||||
|
|
||||||
flags := cmd.Flags()
|
flags := cmd.Flags()
|
||||||
|
|
|
@ -37,7 +37,7 @@ func newPruneCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
return runPrune(dockerCli, options)
|
return runPrune(dockerCli, options)
|
||||||
},
|
},
|
||||||
Tags: map[string]string{"version": "1.25"},
|
Annotations: map[string]string{"version": "1.25"},
|
||||||
}
|
}
|
||||||
|
|
||||||
flags := cmd.Flags()
|
flags := cmd.Flags()
|
||||||
|
|
|
@ -13,7 +13,7 @@ func NewVolumeCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
Short: "Manage volumes",
|
Short: "Manage volumes",
|
||||||
Args: cli.NoArgs,
|
Args: cli.NoArgs,
|
||||||
RunE: command.ShowHelp(dockerCli.Err()),
|
RunE: command.ShowHelp(dockerCli.Err()),
|
||||||
Tags: map[string]string{"version": "1.21"},
|
Annotations: map[string]string{"version": "1.21"},
|
||||||
}
|
}
|
||||||
cmd.AddCommand(
|
cmd.AddCommand(
|
||||||
newCreateCommand(dockerCli),
|
newCreateCommand(dockerCli),
|
||||||
|
|
|
@ -35,7 +35,7 @@ func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
|
||||||
fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed)))
|
fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed)))
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
Tags: map[string]string{"version": "1.25"},
|
Annotations: map[string]string{"version": "1.25"},
|
||||||
}
|
}
|
||||||
|
|
||||||
flags := cmd.Flags()
|
flags := cmd.Flags()
|
||||||
|
|
|
@ -88,6 +88,7 @@ func setFlagErrorFunc(dockerCli *command.DockerCli, cmd *cobra.Command, flags *p
|
||||||
}
|
}
|
||||||
|
|
||||||
func setHelpFunc(dockerCli *command.DockerCli, cmd *cobra.Command, flags *pflag.FlagSet, opts *cliflags.ClientOptions) {
|
func setHelpFunc(dockerCli *command.DockerCli, cmd *cobra.Command, flags *pflag.FlagSet, opts *cliflags.ClientOptions) {
|
||||||
|
defaultHelpFunc := cmd.HelpFunc()
|
||||||
cmd.SetHelpFunc(func(ccmd *cobra.Command, args []string) {
|
cmd.SetHelpFunc(func(ccmd *cobra.Command, args []string) {
|
||||||
initializeDockerCli(dockerCli, flags, opts)
|
initializeDockerCli(dockerCli, flags, opts)
|
||||||
if err := isSupported(ccmd, dockerCli); err != nil {
|
if err := isSupported(ccmd, dockerCli); err != nil {
|
||||||
|
@ -96,10 +97,7 @@ func setHelpFunc(dockerCli *command.DockerCli, cmd *cobra.Command, flags *pflag.
|
||||||
}
|
}
|
||||||
|
|
||||||
hideUnsupportedFeatures(ccmd, dockerCli)
|
hideUnsupportedFeatures(ccmd, dockerCli)
|
||||||
|
defaultHelpFunc(ccmd, args)
|
||||||
if err := ccmd.Help(); err != nil {
|
|
||||||
ccmd.Println(err)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,13 +223,13 @@ func hideUnsupportedFeatures(cmd *cobra.Command, details versionDetails) {
|
||||||
for _, subcmd := range cmd.Commands() {
|
for _, subcmd := range cmd.Commands() {
|
||||||
// hide experimental subcommands
|
// hide experimental subcommands
|
||||||
if !hasExperimental {
|
if !hasExperimental {
|
||||||
if _, ok := subcmd.Tags["experimental"]; ok {
|
if _, ok := subcmd.Annotations["experimental"]; ok {
|
||||||
subcmd.Hidden = true
|
subcmd.Hidden = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// hide subcommands not supported by the server
|
// hide subcommands not supported by the server
|
||||||
if subcmdVersion, ok := subcmd.Tags["version"]; ok && versions.LessThan(clientVersion, subcmdVersion) {
|
if subcmdVersion, ok := subcmd.Annotations["version"]; ok && versions.LessThan(clientVersion, subcmdVersion) {
|
||||||
subcmd.Hidden = true
|
subcmd.Hidden = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -244,10 +242,10 @@ func isSupported(cmd *cobra.Command, details versionDetails) error {
|
||||||
|
|
||||||
// Check recursively so that, e.g., `docker stack ls` returns the same output as `docker stack`
|
// Check recursively so that, e.g., `docker stack ls` returns the same output as `docker stack`
|
||||||
for curr := cmd; curr != nil; curr = curr.Parent() {
|
for curr := cmd; curr != nil; curr = curr.Parent() {
|
||||||
if cmdVersion, ok := curr.Tags["version"]; ok && versions.LessThan(clientVersion, cmdVersion) {
|
if cmdVersion, ok := curr.Annotations["version"]; ok && versions.LessThan(clientVersion, cmdVersion) {
|
||||||
return fmt.Errorf("%s requires API version %s, but the Docker daemon API version is %s", cmd.CommandPath(), cmdVersion, clientVersion)
|
return fmt.Errorf("%s requires API version %s, but the Docker daemon API version is %s", cmd.CommandPath(), cmdVersion, clientVersion)
|
||||||
}
|
}
|
||||||
if _, ok := curr.Tags["experimental"]; ok && !hasExperimental {
|
if _, ok := curr.Annotations["experimental"]; ok && !hasExperimental {
|
||||||
return fmt.Errorf("%s is only supported on a Docker daemon with experimental features enabled", cmd.CommandPath())
|
return fmt.Errorf("%s is only supported on a Docker daemon with experimental features enabled", cmd.CommandPath())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -300,7 +298,7 @@ func isOSTypeSupported(f *pflag.Flag, osType string) bool {
|
||||||
// hasTags return true if any of the command's parents has tags
|
// hasTags return true if any of the command's parents has tags
|
||||||
func hasTags(cmd *cobra.Command) bool {
|
func hasTags(cmd *cobra.Command) bool {
|
||||||
for curr := cmd; curr != nil; curr = curr.Parent() {
|
for curr := cmd; curr != nil; curr = curr.Parent() {
|
||||||
if len(curr.Tags) > 0 {
|
if len(curr.Annotations) > 0 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ func GenYamlTree(cmd *cobra.Command, dir string) error {
|
||||||
// GenYamlTreeCustom creates yaml structured ref files
|
// GenYamlTreeCustom creates yaml structured ref files
|
||||||
func GenYamlTreeCustom(cmd *cobra.Command, dir string, filePrepender func(string) string) error {
|
func GenYamlTreeCustom(cmd *cobra.Command, dir string, filePrepender func(string) string) error {
|
||||||
for _, c := range cmd.Commands() {
|
for _, c := range cmd.Commands() {
|
||||||
if !c.IsAvailableCommand() || c.IsHelpCommand() {
|
if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err := GenYamlTreeCustom(c, dir, filePrepender); err != nil {
|
if err := GenYamlTreeCustom(c, dir, filePrepender); err != nil {
|
||||||
|
@ -103,10 +103,10 @@ func GenYamlCustom(cmd *cobra.Command, w io.Writer) error {
|
||||||
}
|
}
|
||||||
// Check recursively so that, e.g., `docker stack ls` returns the same output as `docker stack`
|
// Check recursively so that, e.g., `docker stack ls` returns the same output as `docker stack`
|
||||||
for curr := cmd; curr != nil; curr = curr.Parent() {
|
for curr := cmd; curr != nil; curr = curr.Parent() {
|
||||||
if v, ok := curr.Tags["version"]; ok && cliDoc.MinAPIVersion == "" {
|
if v, ok := curr.Annotations["version"]; ok && cliDoc.MinAPIVersion == "" {
|
||||||
cliDoc.MinAPIVersion = v
|
cliDoc.MinAPIVersion = v
|
||||||
}
|
}
|
||||||
if _, ok := curr.Tags["experimental"]; ok && !cliDoc.Experimental {
|
if _, ok := curr.Annotations["experimental"]; ok && !cliDoc.Experimental {
|
||||||
cliDoc.Experimental = true
|
cliDoc.Experimental = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ func GenYamlCustom(cmd *cobra.Command, w io.Writer) error {
|
||||||
sort.Sort(byName(children))
|
sort.Sort(byName(children))
|
||||||
|
|
||||||
for _, child := range children {
|
for _, child := range children {
|
||||||
if !child.IsAvailableCommand() || child.IsHelpCommand() {
|
if !child.IsAvailableCommand() || child.IsAdditionalHelpTopicCommand() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
currentChild := cliDoc.Name + " " + child.Name()
|
currentChild := cliDoc.Name + " " + child.Name()
|
||||||
|
@ -207,7 +207,7 @@ func hasSeeAlso(cmd *cobra.Command) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
for _, c := range cmd.Commands() {
|
for _, c := range cmd.Commands() {
|
||||||
if !c.IsAvailableCommand() || c.IsHelpCommand() {
|
if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|
Loading…
Reference in New Issue