always add but hide experimental cmds and flags

Signed-off-by: Victor Vieux <vieux@docker.com>

update cobra and use Tags

Signed-off-by: Victor Vieux <vieux@docker.com>

allow client to talk to an older server

Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
Victor Vieux 2016-11-02 17:43:32 -07:00
parent 086c47f5ee
commit 4ae7176ffb
23 changed files with 75 additions and 52 deletions

View File

@ -1,8 +1,6 @@
package checkpoint package checkpoint
import ( import (
"fmt"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -15,9 +13,10 @@ func NewCheckpointCommand(dockerCli *command.DockerCli) *cobra.Command {
Short: "Manage checkpoints", Short: "Manage checkpoints",
Args: cli.NoArgs, Args: cli.NoArgs,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString()) cmd.SetOutput(dockerCli.Err())
cmd.HelpFunc()(cmd, args)
}, },
Tags: map[string]string{"experimental": ""}, Tags: map[string]string{"experimental": "", "version": "1.25"},
} }
cmd.AddCommand( cmd.AddCommand(
newCreateCommand(dockerCli), newCreateCommand(dockerCli),

View File

@ -10,6 +10,7 @@ import (
"runtime" "runtime"
"github.com/docker/docker/api" "github.com/docker/docker/api"
"github.com/docker/docker/api/types/versions"
cliflags "github.com/docker/docker/cli/flags" cliflags "github.com/docker/docker/cli/flags"
"github.com/docker/docker/cliconfig" "github.com/docker/docker/cliconfig"
"github.com/docker/docker/cliconfig/configfile" "github.com/docker/docker/cliconfig/configfile"
@ -38,15 +39,18 @@ type DockerCli struct {
err io.Writer err io.Writer
keyFile string keyFile string
client client.APIClient client client.APIClient
hasExperimental bool
defaultVersion string
} }
// HasExperimental returns true if experimental features are accessible // HasExperimental returns true if experimental features are accessible.
func (cli *DockerCli) HasExperimental() bool { func (cli *DockerCli) HasExperimental() bool {
if cli.client == nil { return cli.hasExperimental
return false
} }
enabled, _ := cli.client.Ping(context.Background())
return enabled // DefaultVersion returns api.defaultVersion of DOCKER_API_VERSION if specified.
func (cli *DockerCli) DefaultVersion() string {
return cli.defaultVersion
} }
// Client returns the APIClient // Client returns the APIClient
@ -93,12 +97,28 @@ func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions) error {
if err != nil { if err != nil {
return err return err
} }
cli.defaultVersion = cli.client.ClientVersion()
if opts.Common.TrustKey == "" { if opts.Common.TrustKey == "" {
cli.keyFile = filepath.Join(cliconfig.ConfigDir(), cliflags.DefaultTrustKeyFile) cli.keyFile = filepath.Join(cliconfig.ConfigDir(), cliflags.DefaultTrustKeyFile)
} else { } else {
cli.keyFile = opts.Common.TrustKey cli.keyFile = opts.Common.TrustKey
} }
if ping, err := cli.client.Ping(context.Background()); err == nil {
cli.hasExperimental = ping.Experimental
// since the new header was added in 1.25, assume server is 1.24 if header is not present.
if ping.APIVersion == "" {
ping.APIVersion = "1.24"
}
// if server version is lower than the current cli, downgrade
if versions.LessThan(ping.APIVersion, cli.client.ClientVersion()) {
cli.client.UpdateClientVersion(ping.APIVersion)
}
}
return nil return nil
} }

View File

@ -1,8 +1,6 @@
package container package container
import ( import (
"fmt"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
@ -16,7 +14,8 @@ func NewContainerCommand(dockerCli *command.DockerCli) *cobra.Command {
Short: "Manage containers", Short: "Manage containers",
Args: cli.NoArgs, Args: cli.NoArgs,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString()) cmd.SetOutput(dockerCli.Err())
cmd.HelpFunc()(cmd, args)
}, },
} }
cmd.AddCommand( cmd.AddCommand(

View File

@ -59,6 +59,7 @@ func NewExecCommand(dockerCli *command.DockerCli) *cobra.Command {
flags.StringVarP(&opts.user, "user", "u", "", "Username or UID (format: <name|uid>[:<group|gid>])") flags.StringVarP(&opts.user, "user", "u", "", "Username or UID (format: <name|uid>[:<group|gid>])")
flags.BoolVarP(&opts.privileged, "privileged", "", false, "Give extended privileges to the command") flags.BoolVarP(&opts.privileged, "privileged", "", false, "Give extended privileges to the command")
flags.VarP(opts.env, "env", "e", "Set environment variables") flags.VarP(opts.env, "env", "e", "Set environment variables")
flags.SetAnnotation("env", "version", []string{"1.25"})
return cmd return cmd
} }

View File

@ -35,6 +35,7 @@ func NewPruneCommand(dockerCli *command.DockerCli) *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"},
} }
flags := cmd.Flags() flags := cmd.Flags()

View File

@ -113,6 +113,7 @@ func NewBuildCommand(dockerCli *command.DockerCli) *cobra.Command {
flags.BoolVar(&options.squash, "squash", false, "Squash newly built layers into a single new layer") flags.BoolVar(&options.squash, "squash", false, "Squash newly built layers into a single new layer")
flags.SetAnnotation("squash", "experimental", nil) flags.SetAnnotation("squash", "experimental", nil)
flags.SetAnnotation("squash", "version", []string{"1.25"})
return cmd return cmd
} }

View File

@ -1,8 +1,6 @@
package image package image
import ( import (
"fmt"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
@ -16,7 +14,8 @@ func NewImageCommand(dockerCli *command.DockerCli) *cobra.Command {
Short: "Manage images", Short: "Manage images",
Args: cli.NoArgs, Args: cli.NoArgs,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString()) cmd.SetOutput(dockerCli.Err())
cmd.HelpFunc()(cmd, args)
}, },
} }
cmd.AddCommand( cmd.AddCommand(
@ -33,6 +32,5 @@ func NewImageCommand(dockerCli *command.DockerCli) *cobra.Command {
newInspectCommand(dockerCli), newInspectCommand(dockerCli),
NewPruneCommand(dockerCli), NewPruneCommand(dockerCli),
) )
return cmd return cmd
} }

View File

@ -36,6 +36,7 @@ func NewPruneCommand(dockerCli *command.DockerCli) *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"},
} }
flags := cmd.Flags() flags := cmd.Flags()

View File

@ -1,8 +1,6 @@
package network package network
import ( import (
"fmt"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
@ -16,7 +14,8 @@ func NewNetworkCommand(dockerCli *command.DockerCli) *cobra.Command {
Short: "Manage networks", Short: "Manage networks",
Args: cli.NoArgs, Args: cli.NoArgs,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString()) cmd.SetOutput(dockerCli.Err())
cmd.HelpFunc()(cmd, args)
}, },
} }
cmd.AddCommand( cmd.AddCommand(

View File

@ -33,6 +33,7 @@ func NewPruneCommand(dockerCli *command.DockerCli) *cobra.Command {
} }
return nil return nil
}, },
Tags: map[string]string{"version": "1.25"},
} }
flags := cmd.Flags() flags := cmd.Flags()

View File

@ -1,8 +1,6 @@
package node package node
import ( import (
"fmt"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
apiclient "github.com/docker/docker/client" apiclient "github.com/docker/docker/client"
@ -17,7 +15,8 @@ func NewNodeCommand(dockerCli *command.DockerCli) *cobra.Command {
Short: "Manage Swarm nodes", Short: "Manage Swarm nodes",
Args: cli.NoArgs, Args: cli.NoArgs,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString()) cmd.SetOutput(dockerCli.Err())
cmd.HelpFunc()(cmd, args)
}, },
} }
cmd.AddCommand( cmd.AddCommand(

View File

@ -1,8 +1,6 @@
package plugin package plugin
import ( import (
"fmt"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -15,7 +13,8 @@ func NewPluginCommand(dockerCli *command.DockerCli) *cobra.Command {
Short: "Manage plugins", Short: "Manage plugins",
Args: cli.NoArgs, Args: cli.NoArgs,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString()) cmd.SetOutput(dockerCli.Err())
cmd.HelpFunc()(cmd, args)
}, },
Tags: map[string]string{"experimental": ""}, Tags: map[string]string{"experimental": ""},
} }

View File

@ -1,8 +1,6 @@
package service package service
import ( import (
"fmt"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
@ -16,7 +14,8 @@ func NewServiceCommand(dockerCli *command.DockerCli) *cobra.Command {
Short: "Manage services", Short: "Manage services",
Args: cli.NoArgs, Args: cli.NoArgs,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString()) cmd.SetOutput(dockerCli.Err())
cmd.HelpFunc()(cmd, args)
}, },
} }
cmd.AddCommand( cmd.AddCommand(

View File

@ -1,8 +1,6 @@
package stack package stack
import ( import (
"fmt"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -15,9 +13,10 @@ func NewStackCommand(dockerCli *command.DockerCli) *cobra.Command {
Short: "Manage Docker stacks", Short: "Manage Docker stacks",
Args: cli.NoArgs, Args: cli.NoArgs,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString()) cmd.SetOutput(dockerCli.Err())
cmd.HelpFunc()(cmd, args)
}, },
Tags: map[string]string{"experimental": ""}, Tags: map[string]string{"experimental": "", "version": "1.25"},
} }
cmd.AddCommand( cmd.AddCommand(
newConfigCommand(dockerCli), newConfigCommand(dockerCli),

View File

@ -36,7 +36,7 @@ func newDeployCommand(dockerCli *command.DockerCli) *cobra.Command {
opts.namespace = strings.TrimSuffix(args[0], ".dab") opts.namespace = strings.TrimSuffix(args[0], ".dab")
return runDeploy(dockerCli, opts) return runDeploy(dockerCli, opts)
}, },
Tags: map[string]string{"experimental": ""}, Tags: map[string]string{"experimental": "", "version": "1.25"},
} }
flags := cmd.Flags() flags := cmd.Flags()

View File

@ -1,8 +1,6 @@
package swarm package swarm
import ( import (
"fmt"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
@ -16,7 +14,8 @@ func NewSwarmCommand(dockerCli *command.DockerCli) *cobra.Command {
Short: "Manage Swarm", Short: "Manage Swarm",
Args: cli.NoArgs, Args: cli.NoArgs,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString()) cmd.SetOutput(dockerCli.Err())
cmd.HelpFunc()(cmd, args)
}, },
} }
cmd.AddCommand( cmd.AddCommand(

View File

@ -1,8 +1,6 @@
package system package system
import ( import (
"fmt"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
@ -16,7 +14,8 @@ func NewSystemCommand(dockerCli *command.DockerCli) *cobra.Command {
Short: "Manage Docker", Short: "Manage Docker",
Args: cli.NoArgs, Args: cli.NoArgs,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString()) cmd.SetOutput(dockerCli.Err())
cmd.HelpFunc()(cmd, args)
}, },
} }
cmd.AddCommand( cmd.AddCommand(
@ -25,5 +24,6 @@ func NewSystemCommand(dockerCli *command.DockerCli) *cobra.Command {
NewDiskUsageCommand(dockerCli), NewDiskUsageCommand(dockerCli),
NewPruneCommand(dockerCli), NewPruneCommand(dockerCli),
) )
return cmd return cmd
} }

View File

@ -23,6 +23,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"},
} }
flags := cmd.Flags() flags := cmd.Flags()

View File

@ -26,6 +26,7 @@ func NewPruneCommand(dockerCli *command.DockerCli) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return runPrune(dockerCli, opts) return runPrune(dockerCli, opts)
}, },
Tags: map[string]string{"version": "1.25"},
} }
flags := cmd.Flags() flags := cmd.Flags()

View File

@ -1,6 +1,7 @@
package system package system
import ( import (
"fmt"
"runtime" "runtime"
"time" "time"
@ -70,10 +71,15 @@ func runVersion(dockerCli *command.DockerCli, opts *versionOptions) error {
Status: "Template parsing error: " + err.Error()} Status: "Template parsing error: " + err.Error()}
} }
APIVersion := dockerCli.Client().ClientVersion()
if defaultAPIVersion := dockerCli.DefaultVersion(); APIVersion != defaultAPIVersion {
APIVersion = fmt.Sprintf("%s (downgraded from %s)", APIVersion, defaultAPIVersion)
}
vd := types.VersionResponse{ vd := types.VersionResponse{
Client: &types.Version{ Client: &types.Version{
Version: dockerversion.Version, Version: dockerversion.Version,
APIVersion: dockerCli.Client().ClientVersion(), APIVersion: APIVersion,
GoVersion: runtime.Version(), GoVersion: runtime.Version(),
GitCommit: dockerversion.GitCommit, GitCommit: dockerversion.GitCommit,
BuildTime: dockerversion.BuildTime, BuildTime: dockerversion.BuildTime,

View File

@ -1,8 +1,6 @@
package volume package volume
import ( import (
"fmt"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
@ -17,7 +15,8 @@ func NewVolumeCommand(dockerCli *command.DockerCli) *cobra.Command {
Long: volumeDescription, Long: volumeDescription,
Args: cli.NoArgs, Args: cli.NoArgs,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString()) cmd.SetOutput(dockerCli.Err())
cmd.HelpFunc()(cmd, args)
}, },
} }
cmd.AddCommand( cmd.AddCommand(

View File

@ -35,6 +35,7 @@ func NewPruneCommand(dockerCli *command.DockerCli) *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"},
} }
flags := cmd.Flags() flags := cmd.Flags()

View File

@ -34,7 +34,7 @@ func newRemoveCommand(dockerCli *command.DockerCli) *cobra.Command {
flags := cmd.Flags() flags := cmd.Flags()
flags.BoolVarP(&opts.force, "force", "f", false, "Force the removal of one or more volumes") flags.BoolVarP(&opts.force, "force", "f", false, "Force the removal of one or more volumes")
flags.SetAnnotation("force", "version", []string{"1.25"})
return cmd return cmd
} }