mirror of https://github.com/docker/cli.git
Make experimental a runtime flag
Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
parent
6ec439e875
commit
66bd963b76
|
@ -1,5 +1,3 @@
|
|||
// +build experimental
|
||||
|
||||
package bundlefile
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
// +build experimental
|
||||
|
||||
package bundlefile
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,13 +1,27 @@
|
|||
// +build !experimental
|
||||
|
||||
package checkpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/docker/docker/cli"
|
||||
"github.com/docker/docker/cli/command"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// NewCheckpointCommand returns the `checkpoint` subcommand (only in experimental)
|
||||
func NewCheckpointCommand(dockerCli *command.DockerCli) *cobra.Command {
|
||||
return &cobra.Command{}
|
||||
cmd := &cobra.Command{
|
||||
Use: "checkpoint",
|
||||
Short: "Manage checkpoints",
|
||||
Args: cli.NoArgs,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString())
|
||||
},
|
||||
}
|
||||
cmd.AddCommand(
|
||||
newCreateCommand(dockerCli),
|
||||
newListCommand(dockerCli),
|
||||
newRemoveCommand(dockerCli),
|
||||
)
|
||||
return cmd
|
||||
}
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
// +build experimental
|
||||
|
||||
package checkpoint
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/docker/docker/cli"
|
||||
"github.com/docker/docker/cli/command"
|
||||
)
|
||||
|
||||
// NewCheckpointCommand returns the `checkpoint` subcommand (only in experimental)
|
||||
func NewCheckpointCommand(dockerCli *command.DockerCli) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "checkpoint",
|
||||
Short: "Manage checkpoints",
|
||||
Args: cli.NoArgs,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString())
|
||||
},
|
||||
}
|
||||
cmd.AddCommand(
|
||||
newCreateCommand(dockerCli),
|
||||
newListCommand(dockerCli),
|
||||
newRemoveCommand(dockerCli),
|
||||
)
|
||||
return cmd
|
||||
}
|
|
@ -1,5 +1,3 @@
|
|||
// +build experimental
|
||||
|
||||
package checkpoint
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
// +build experimental
|
||||
|
||||
package checkpoint
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
// +build experimental
|
||||
|
||||
package checkpoint
|
||||
|
||||
import (
|
||||
|
|
|
@ -19,6 +19,7 @@ import (
|
|||
dopts "github.com/docker/docker/opts"
|
||||
"github.com/docker/go-connections/sockets"
|
||||
"github.com/docker/go-connections/tlsconfig"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// Streams is an interface which exposes the standard input and output streams
|
||||
|
@ -31,12 +32,27 @@ type Streams interface {
|
|||
// DockerCli represents the docker command line client.
|
||||
// Instances of the client can be returned from NewDockerCli.
|
||||
type DockerCli struct {
|
||||
configFile *configfile.ConfigFile
|
||||
in *InStream
|
||||
out *OutStream
|
||||
err io.Writer
|
||||
keyFile string
|
||||
client client.APIClient
|
||||
configFile *configfile.ConfigFile
|
||||
in *InStream
|
||||
out *OutStream
|
||||
err io.Writer
|
||||
keyFile string
|
||||
client client.APIClient
|
||||
hasExperimental *bool
|
||||
}
|
||||
|
||||
// HasExperimental returns true if experimental features are accessible
|
||||
func (cli *DockerCli) HasExperimental() bool {
|
||||
if cli.hasExperimental == nil {
|
||||
if cli.client == nil {
|
||||
cli.Initialize(cliflags.NewClientOptions())
|
||||
}
|
||||
enabled := false
|
||||
cli.hasExperimental = &enabled
|
||||
enabled, _ = cli.client.Ping(context.Background())
|
||||
}
|
||||
|
||||
return *cli.hasExperimental
|
||||
}
|
||||
|
||||
// Client returns the APIClient
|
||||
|
|
|
@ -24,8 +24,6 @@ func AddCommands(cmd *cobra.Command, dockerCli *command.DockerCli) {
|
|||
cmd.AddCommand(
|
||||
node.NewNodeCommand(dockerCli),
|
||||
service.NewServiceCommand(dockerCli),
|
||||
stack.NewStackCommand(dockerCli),
|
||||
stack.NewTopLevelDeployCommand(dockerCli),
|
||||
swarm.NewSwarmCommand(dockerCli),
|
||||
container.NewContainerCommand(dockerCli),
|
||||
image.NewImageCommand(dockerCli),
|
||||
|
@ -72,9 +70,17 @@ func AddCommands(cmd *cobra.Command, dockerCli *command.DockerCli) {
|
|||
hide(image.NewSaveCommand(dockerCli)),
|
||||
hide(image.NewTagCommand(dockerCli)),
|
||||
hide(system.NewInspectCommand(dockerCli)),
|
||||
checkpoint.NewCheckpointCommand(dockerCli),
|
||||
plugin.NewPluginCommand(dockerCli),
|
||||
)
|
||||
|
||||
if dockerCli.HasExperimental() {
|
||||
cmd.AddCommand(
|
||||
stack.NewStackCommand(dockerCli),
|
||||
stack.NewTopLevelDeployCommand(dockerCli),
|
||||
checkpoint.NewCheckpointCommand(dockerCli),
|
||||
plugin.NewPluginCommand(dockerCli),
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func hide(cmd *cobra.Command) *cobra.Command {
|
||||
|
|
|
@ -44,7 +44,9 @@ func NewStartCommand(dockerCli *command.DockerCli) *cobra.Command {
|
|||
flags.BoolVarP(&opts.openStdin, "interactive", "i", false, "Attach container's STDIN")
|
||||
flags.StringVar(&opts.detachKeys, "detach-keys", "", "Override the key sequence for detaching a container")
|
||||
|
||||
addExperimentalStartFlags(flags, &opts)
|
||||
if dockerCli.HasExperimental() {
|
||||
flags.StringVar(&opts.checkpoint, "checkpoint", "", "Restore from this checkpoint")
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
// +build !experimental
|
||||
|
||||
package container
|
||||
|
||||
import "github.com/spf13/pflag"
|
||||
|
||||
func addExperimentalStartFlags(flags *pflag.FlagSet, opts *startOptions) {
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
// +build experimental
|
||||
|
||||
package container
|
||||
|
||||
import "github.com/spf13/pflag"
|
||||
|
||||
func addExperimentalStartFlags(flags *pflag.FlagSet, opts *startOptions) {
|
||||
flags.StringVar(&opts.checkpoint, "checkpoint", "", "Restore from this checkpoint")
|
||||
}
|
|
@ -1,13 +1,33 @@
|
|||
// +build !experimental
|
||||
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/docker/docker/cli"
|
||||
"github.com/docker/docker/cli/command"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// NewPluginCommand returns a cobra command for `plugin` subcommands
|
||||
func NewPluginCommand(dockerCli *command.DockerCli) *cobra.Command {
|
||||
return &cobra.Command{}
|
||||
cmd := &cobra.Command{
|
||||
Use: "plugin",
|
||||
Short: "Manage plugins",
|
||||
Args: cli.NoArgs,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString())
|
||||
},
|
||||
}
|
||||
|
||||
cmd.AddCommand(
|
||||
newDisableCommand(dockerCli),
|
||||
newEnableCommand(dockerCli),
|
||||
newInspectCommand(dockerCli),
|
||||
newInstallCommand(dockerCli),
|
||||
newListCommand(dockerCli),
|
||||
newRemoveCommand(dockerCli),
|
||||
newSetCommand(dockerCli),
|
||||
newPushCommand(dockerCli),
|
||||
)
|
||||
return cmd
|
||||
}
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
// +build experimental
|
||||
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/docker/docker/cli"
|
||||
"github.com/docker/docker/cli/command"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// NewPluginCommand returns a cobra command for `plugin` subcommands
|
||||
func NewPluginCommand(dockerCli *command.DockerCli) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "plugin",
|
||||
Short: "Manage plugins",
|
||||
Args: cli.NoArgs,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString())
|
||||
},
|
||||
}
|
||||
|
||||
cmd.AddCommand(
|
||||
newDisableCommand(dockerCli),
|
||||
newEnableCommand(dockerCli),
|
||||
newInspectCommand(dockerCli),
|
||||
newInstallCommand(dockerCli),
|
||||
newListCommand(dockerCli),
|
||||
newRemoveCommand(dockerCli),
|
||||
newSetCommand(dockerCli),
|
||||
newPushCommand(dockerCli),
|
||||
)
|
||||
return cmd
|
||||
}
|
|
@ -1,5 +1,3 @@
|
|||
// +build experimental
|
||||
|
||||
package plugin
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
// +build experimental
|
||||
|
||||
package plugin
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
// +build experimental
|
||||
|
||||
package plugin
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
// +build experimental
|
||||
|
||||
package plugin
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
// +build experimental
|
||||
|
||||
package plugin
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
// +build experimental
|
||||
|
||||
package plugin
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
// +build experimental
|
||||
|
||||
package plugin
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
// +build experimental
|
||||
|
||||
package plugin
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,18 +1,38 @@
|
|||
// +build !experimental
|
||||
|
||||
package stack
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/docker/docker/cli"
|
||||
"github.com/docker/docker/cli/command"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// NewStackCommand returns no command
|
||||
// NewStackCommand returns a cobra command for `stack` subcommands
|
||||
func NewStackCommand(dockerCli *command.DockerCli) *cobra.Command {
|
||||
return &cobra.Command{}
|
||||
cmd := &cobra.Command{
|
||||
Use: "stack",
|
||||
Short: "Manage Docker stacks",
|
||||
Args: cli.NoArgs,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString())
|
||||
},
|
||||
}
|
||||
cmd.AddCommand(
|
||||
newConfigCommand(dockerCli),
|
||||
newDeployCommand(dockerCli),
|
||||
newListCommand(dockerCli),
|
||||
newRemoveCommand(dockerCli),
|
||||
newServicesCommand(dockerCli),
|
||||
newPsCommand(dockerCli),
|
||||
)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// NewTopLevelDeployCommand returns no command
|
||||
// NewTopLevelDeployCommand returns a command for `docker deploy`
|
||||
func NewTopLevelDeployCommand(dockerCli *command.DockerCli) *cobra.Command {
|
||||
return &cobra.Command{}
|
||||
cmd := newDeployCommand(dockerCli)
|
||||
// Remove the aliases at the top level
|
||||
cmd.Aliases = []string{}
|
||||
return cmd
|
||||
}
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
// +build experimental
|
||||
|
||||
package stack
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/docker/docker/cli"
|
||||
"github.com/docker/docker/cli/command"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// NewStackCommand returns a cobra command for `stack` subcommands
|
||||
func NewStackCommand(dockerCli *command.DockerCli) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "stack",
|
||||
Short: "Manage Docker stacks",
|
||||
Args: cli.NoArgs,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString())
|
||||
},
|
||||
}
|
||||
cmd.AddCommand(
|
||||
newConfigCommand(dockerCli),
|
||||
newDeployCommand(dockerCli),
|
||||
newListCommand(dockerCli),
|
||||
newRemoveCommand(dockerCli),
|
||||
newServicesCommand(dockerCli),
|
||||
newPsCommand(dockerCli),
|
||||
)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// NewTopLevelDeployCommand returns a command for `docker deploy`
|
||||
func NewTopLevelDeployCommand(dockerCli *command.DockerCli) *cobra.Command {
|
||||
cmd := newDeployCommand(dockerCli)
|
||||
// Remove the aliases at the top level
|
||||
cmd.Aliases = []string{}
|
||||
return cmd
|
||||
}
|
|
@ -1,5 +1,3 @@
|
|||
// +build experimental
|
||||
|
||||
package stack
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
// +build experimental
|
||||
|
||||
package stack
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
// +build experimental
|
||||
|
||||
package stack
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
// +build experimental
|
||||
|
||||
package stack
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
// +build experimental
|
||||
|
||||
package stack
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
// +build experimental
|
||||
|
||||
package stack
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
// +build experimental
|
||||
|
||||
package stack
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
// +build experimental
|
||||
|
||||
package stack
|
||||
|
||||
import (
|
||||
|
|
|
@ -225,7 +225,7 @@ func prettyPrintInfo(dockerCli *command.DockerCli, info types.Info) error {
|
|||
}
|
||||
}
|
||||
|
||||
ioutils.FprintfIfTrue(dockerCli.Out(), "Experimental: %v\n", info.ExperimentalBuild)
|
||||
fmt.Fprintf(dockerCli.Out(), "Experimental: %v\n", info.ExperimentalBuild)
|
||||
if info.ClusterStore != "" {
|
||||
fmt.Fprintf(dockerCli.Out(), "Cluster Store: %s\n", info.ClusterStore)
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ import (
|
|||
"github.com/docker/docker/cli"
|
||||
"github.com/docker/docker/cli/command"
|
||||
"github.com/docker/docker/dockerversion"
|
||||
"github.com/docker/docker/utils"
|
||||
"github.com/docker/docker/utils/templates"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
@ -21,8 +20,7 @@ var versionTemplate = `Client:
|
|||
Go version: {{.Client.GoVersion}}
|
||||
Git commit: {{.Client.GitCommit}}
|
||||
Built: {{.Client.BuildTime}}
|
||||
OS/Arch: {{.Client.Os}}/{{.Client.Arch}}{{if .Client.Experimental}}
|
||||
Experimental: {{.Client.Experimental}}{{end}}{{if .ServerOK}}
|
||||
OS/Arch: {{.Client.Os}}/{{.Client.Arch}}{{if .ServerOK}}
|
||||
|
||||
Server:
|
||||
Version: {{.Server.Version}}
|
||||
|
@ -30,8 +28,8 @@ Server:
|
|||
Go version: {{.Server.GoVersion}}
|
||||
Git commit: {{.Server.GitCommit}}
|
||||
Built: {{.Server.BuildTime}}
|
||||
OS/Arch: {{.Server.Os}}/{{.Server.Arch}}{{if .Server.Experimental}}
|
||||
Experimental: {{.Server.Experimental}}{{end}}{{end}}`
|
||||
OS/Arch: {{.Server.Os}}/{{.Server.Arch}}
|
||||
Experimental: {{.Server.Experimental}}{{end}}`
|
||||
|
||||
type versionOptions struct {
|
||||
format string
|
||||
|
@ -73,14 +71,13 @@ func runVersion(dockerCli *command.DockerCli, opts *versionOptions) error {
|
|||
|
||||
vd := types.VersionResponse{
|
||||
Client: &types.Version{
|
||||
Version: dockerversion.Version,
|
||||
APIVersion: dockerCli.Client().ClientVersion(),
|
||||
GoVersion: runtime.Version(),
|
||||
GitCommit: dockerversion.GitCommit,
|
||||
BuildTime: dockerversion.BuildTime,
|
||||
Os: runtime.GOOS,
|
||||
Arch: runtime.GOARCH,
|
||||
Experimental: utils.ExperimentalBuild(),
|
||||
Version: dockerversion.Version,
|
||||
APIVersion: dockerCli.Client().ClientVersion(),
|
||||
GoVersion: runtime.Version(),
|
||||
GitCommit: dockerversion.GitCommit,
|
||||
BuildTime: dockerversion.BuildTime,
|
||||
Os: runtime.GOOS,
|
||||
Arch: runtime.GOARCH,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue