فهرست منبع

Cleanup the structure of the cli package.

Move all flags into cli/flags
Move usage help into cli/usage.go

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Daniel Nephin 9 سال پیش
والد
کامیت
33c9edaf6c
8فایلهای تغییر یافته به همراه39 افزوده شده و 47 حذف شده
  1. 2 2
      api/client/cli.go
  2. 1 1
      cli/flags/client.go
  3. 17 4
      cli/flags/common.go
  4. 0 19
      cli/usage.go
  5. 1 2
      cmd/docker/client.go
  6. 2 3
      cmd/dockerd/daemon.go
  7. 10 10
      cmd/dockerd/daemon_test.go
  8. 6 6
      cmd/dockerd/daemon_unix_test.go

+ 2 - 2
api/client/cli.go

@@ -9,7 +9,7 @@ import (
 	"runtime"
 	"runtime"
 
 
 	"github.com/docker/docker/api"
 	"github.com/docker/docker/api"
-	"github.com/docker/docker/cli"
+	cliflags "github.com/docker/docker/cli/flags"
 	"github.com/docker/docker/cliconfig"
 	"github.com/docker/docker/cliconfig"
 	"github.com/docker/docker/cliconfig/credentials"
 	"github.com/docker/docker/cliconfig/credentials"
 	"github.com/docker/docker/dockerversion"
 	"github.com/docker/docker/dockerversion"
@@ -112,7 +112,7 @@ func (cli *DockerCli) restoreTerminal(in io.Closer) error {
 // The key file, protocol (i.e. unix) and address are passed in as strings, along with the tls.Config. If the tls.Config
 // The key file, protocol (i.e. unix) and address are passed in as strings, along with the tls.Config. If the tls.Config
 // is set the client scheme will be set to https.
 // is set the client scheme will be set to https.
 // The client will be given a 32-second timeout (see https://github.com/docker/docker/pull/8035).
 // The client will be given a 32-second timeout (see https://github.com/docker/docker/pull/8035).
-func NewDockerCli(in io.ReadCloser, out, err io.Writer, clientFlags *cli.ClientFlags) *DockerCli {
+func NewDockerCli(in io.ReadCloser, out, err io.Writer, clientFlags *cliflags.ClientFlags) *DockerCli {
 	cli := &DockerCli{
 	cli := &DockerCli{
 		in:      in,
 		in:      in,
 		out:     out,
 		out:     out,

+ 1 - 1
cli/client.go → cli/flags/client.go

@@ -1,4 +1,4 @@
-package cli
+package flags
 
 
 import flag "github.com/docker/docker/pkg/mflag"
 import flag "github.com/docker/docker/pkg/mflag"
 
 

+ 17 - 4
cli/flags/common.go

@@ -6,7 +6,6 @@ import (
 	"path/filepath"
 	"path/filepath"
 
 
 	"github.com/Sirupsen/logrus"
 	"github.com/Sirupsen/logrus"
-	"github.com/docker/docker/cli"
 	"github.com/docker/docker/cliconfig"
 	"github.com/docker/docker/cliconfig"
 	"github.com/docker/docker/opts"
 	"github.com/docker/docker/opts"
 	flag "github.com/docker/docker/pkg/mflag"
 	flag "github.com/docker/docker/pkg/mflag"
@@ -31,9 +30,23 @@ var (
 	dockerTLSVerify = os.Getenv("DOCKER_TLS_VERIFY") != ""
 	dockerTLSVerify = os.Getenv("DOCKER_TLS_VERIFY") != ""
 )
 )
 
 
+// CommonFlags are flags common to both the client and the daemon.
+type CommonFlags struct {
+	FlagSet   *flag.FlagSet
+	PostParse func()
+
+	Debug      bool
+	Hosts      []string
+	LogLevel   string
+	TLS        bool
+	TLSVerify  bool
+	TLSOptions *tlsconfig.Options
+	TrustKey   string
+}
+
 // InitCommonFlags initializes flags common to both client and daemon
 // InitCommonFlags initializes flags common to both client and daemon
-func InitCommonFlags() *cli.CommonFlags {
-	var commonFlags = &cli.CommonFlags{FlagSet: new(flag.FlagSet)}
+func InitCommonFlags() *CommonFlags {
+	var commonFlags = &CommonFlags{FlagSet: new(flag.FlagSet)}
 
 
 	if dockerCertPath == "" {
 	if dockerCertPath == "" {
 		dockerCertPath = cliconfig.ConfigDir()
 		dockerCertPath = cliconfig.ConfigDir()
@@ -60,7 +73,7 @@ func InitCommonFlags() *cli.CommonFlags {
 	return commonFlags
 	return commonFlags
 }
 }
 
 
-func postParseCommon(commonFlags *cli.CommonFlags) {
+func postParseCommon(commonFlags *CommonFlags) {
 	cmd := commonFlags.FlagSet
 	cmd := commonFlags.FlagSet
 
 
 	SetDaemonLogLevel(commonFlags.LogLevel)
 	SetDaemonLogLevel(commonFlags.LogLevel)

+ 0 - 19
cli/common.go → cli/usage.go

@@ -1,24 +1,5 @@
 package cli
 package cli
 
 
-import (
-	flag "github.com/docker/docker/pkg/mflag"
-	"github.com/docker/go-connections/tlsconfig"
-)
-
-// CommonFlags represents flags that are common to both the client and the daemon.
-type CommonFlags struct {
-	FlagSet   *flag.FlagSet
-	PostParse func()
-
-	Debug      bool
-	Hosts      []string
-	LogLevel   string
-	TLS        bool
-	TLSVerify  bool
-	TLSOptions *tlsconfig.Options
-	TrustKey   string
-}
-
 // Command is the struct containing the command name and description
 // Command is the struct containing the command name and description
 type Command struct {
 type Command struct {
 	Name        string
 	Name        string

+ 1 - 2
cmd/docker/client.go

@@ -3,7 +3,6 @@ package main
 import (
 import (
 	"path/filepath"
 	"path/filepath"
 
 
-	"github.com/docker/docker/cli"
 	cliflags "github.com/docker/docker/cli/flags"
 	cliflags "github.com/docker/docker/cli/flags"
 	"github.com/docker/docker/cliconfig"
 	"github.com/docker/docker/cliconfig"
 	flag "github.com/docker/docker/pkg/mflag"
 	flag "github.com/docker/docker/pkg/mflag"
@@ -12,7 +11,7 @@ import (
 
 
 var (
 var (
 	commonFlags = cliflags.InitCommonFlags()
 	commonFlags = cliflags.InitCommonFlags()
-	clientFlags = &cli.ClientFlags{FlagSet: new(flag.FlagSet), Common: commonFlags}
+	clientFlags = &cliflags.ClientFlags{FlagSet: new(flag.FlagSet), Common: commonFlags}
 )
 )
 
 
 func init() {
 func init() {

+ 2 - 3
cmd/dockerd/daemon.go

@@ -23,7 +23,6 @@ import (
 	systemrouter "github.com/docker/docker/api/server/router/system"
 	systemrouter "github.com/docker/docker/api/server/router/system"
 	"github.com/docker/docker/api/server/router/volume"
 	"github.com/docker/docker/api/server/router/volume"
 	"github.com/docker/docker/builder/dockerfile"
 	"github.com/docker/docker/builder/dockerfile"
-	"github.com/docker/docker/cli"
 	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/daemon"
 	"github.com/docker/docker/daemon"
@@ -51,7 +50,7 @@ const (
 // DaemonCli represents the daemon CLI.
 // DaemonCli represents the daemon CLI.
 type DaemonCli struct {
 type DaemonCli struct {
 	*daemon.Config
 	*daemon.Config
-	commonFlags *cli.CommonFlags
+	commonFlags *cliflags.CommonFlags
 	configFile  *string
 	configFile  *string
 }
 }
 
 
@@ -345,7 +344,7 @@ func shutdownDaemon(d *daemon.Daemon, timeout time.Duration) {
 	}
 	}
 }
 }
 
 
-func loadDaemonCliConfig(config *daemon.Config, flags *flag.FlagSet, commonConfig *cli.CommonFlags, configFile string) (*daemon.Config, error) {
+func loadDaemonCliConfig(config *daemon.Config, flags *flag.FlagSet, commonConfig *cliflags.CommonFlags, configFile string) (*daemon.Config, error) {
 	config.Debug = commonConfig.Debug
 	config.Debug = commonConfig.Debug
 	config.Hosts = commonConfig.Hosts
 	config.Hosts = commonConfig.Hosts
 	config.LogLevel = commonConfig.LogLevel
 	config.LogLevel = commonConfig.LogLevel

+ 10 - 10
cmd/dockerd/daemon_test.go

@@ -7,7 +7,7 @@ import (
 	"testing"
 	"testing"
 
 
 	"github.com/Sirupsen/logrus"
 	"github.com/Sirupsen/logrus"
-	"github.com/docker/docker/cli"
+	cliflags "github.com/docker/docker/cli/flags"
 	"github.com/docker/docker/daemon"
 	"github.com/docker/docker/daemon"
 	"github.com/docker/docker/opts"
 	"github.com/docker/docker/opts"
 	"github.com/docker/docker/pkg/mflag"
 	"github.com/docker/docker/pkg/mflag"
@@ -16,7 +16,7 @@ import (
 
 
 func TestLoadDaemonCliConfigWithoutOverriding(t *testing.T) {
 func TestLoadDaemonCliConfigWithoutOverriding(t *testing.T) {
 	c := &daemon.Config{}
 	c := &daemon.Config{}
-	common := &cli.CommonFlags{
+	common := &cliflags.CommonFlags{
 		Debug: true,
 		Debug: true,
 	}
 	}
 
 
@@ -35,7 +35,7 @@ func TestLoadDaemonCliConfigWithoutOverriding(t *testing.T) {
 
 
 func TestLoadDaemonCliConfigWithTLS(t *testing.T) {
 func TestLoadDaemonCliConfigWithTLS(t *testing.T) {
 	c := &daemon.Config{}
 	c := &daemon.Config{}
-	common := &cli.CommonFlags{
+	common := &cliflags.CommonFlags{
 		TLS: true,
 		TLS: true,
 		TLSOptions: &tlsconfig.Options{
 		TLSOptions: &tlsconfig.Options{
 			CAFile: "/tmp/ca.pem",
 			CAFile: "/tmp/ca.pem",
@@ -57,7 +57,7 @@ func TestLoadDaemonCliConfigWithTLS(t *testing.T) {
 
 
 func TestLoadDaemonCliConfigWithConflicts(t *testing.T) {
 func TestLoadDaemonCliConfigWithConflicts(t *testing.T) {
 	c := &daemon.Config{}
 	c := &daemon.Config{}
-	common := &cli.CommonFlags{}
+	common := &cliflags.CommonFlags{}
 	f, err := ioutil.TempFile("", "docker-config-")
 	f, err := ioutil.TempFile("", "docker-config-")
 	if err != nil {
 	if err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
@@ -93,7 +93,7 @@ func TestLoadDaemonCliConfigWithConflicts(t *testing.T) {
 
 
 func TestLoadDaemonCliConfigWithTLSVerify(t *testing.T) {
 func TestLoadDaemonCliConfigWithTLSVerify(t *testing.T) {
 	c := &daemon.Config{}
 	c := &daemon.Config{}
-	common := &cli.CommonFlags{
+	common := &cliflags.CommonFlags{
 		TLSOptions: &tlsconfig.Options{
 		TLSOptions: &tlsconfig.Options{
 			CAFile: "/tmp/ca.pem",
 			CAFile: "/tmp/ca.pem",
 		},
 		},
@@ -126,7 +126,7 @@ func TestLoadDaemonCliConfigWithTLSVerify(t *testing.T) {
 
 
 func TestLoadDaemonCliConfigWithExplicitTLSVerifyFalse(t *testing.T) {
 func TestLoadDaemonCliConfigWithExplicitTLSVerifyFalse(t *testing.T) {
 	c := &daemon.Config{}
 	c := &daemon.Config{}
-	common := &cli.CommonFlags{
+	common := &cliflags.CommonFlags{
 		TLSOptions: &tlsconfig.Options{
 		TLSOptions: &tlsconfig.Options{
 			CAFile: "/tmp/ca.pem",
 			CAFile: "/tmp/ca.pem",
 		},
 		},
@@ -159,7 +159,7 @@ func TestLoadDaemonCliConfigWithExplicitTLSVerifyFalse(t *testing.T) {
 
 
 func TestLoadDaemonCliConfigWithoutTLSVerify(t *testing.T) {
 func TestLoadDaemonCliConfigWithoutTLSVerify(t *testing.T) {
 	c := &daemon.Config{}
 	c := &daemon.Config{}
-	common := &cli.CommonFlags{
+	common := &cliflags.CommonFlags{
 		TLSOptions: &tlsconfig.Options{
 		TLSOptions: &tlsconfig.Options{
 			CAFile: "/tmp/ca.pem",
 			CAFile: "/tmp/ca.pem",
 		},
 		},
@@ -191,7 +191,7 @@ func TestLoadDaemonCliConfigWithoutTLSVerify(t *testing.T) {
 
 
 func TestLoadDaemonCliConfigWithLogLevel(t *testing.T) {
 func TestLoadDaemonCliConfigWithLogLevel(t *testing.T) {
 	c := &daemon.Config{}
 	c := &daemon.Config{}
-	common := &cli.CommonFlags{}
+	common := &cliflags.CommonFlags{}
 
 
 	f, err := ioutil.TempFile("", "docker-config-")
 	f, err := ioutil.TempFile("", "docker-config-")
 	if err != nil {
 	if err != nil {
@@ -223,7 +223,7 @@ func TestLoadDaemonCliConfigWithLogLevel(t *testing.T) {
 
 
 func TestLoadDaemonConfigWithEmbeddedOptions(t *testing.T) {
 func TestLoadDaemonConfigWithEmbeddedOptions(t *testing.T) {
 	c := &daemon.Config{}
 	c := &daemon.Config{}
-	common := &cli.CommonFlags{}
+	common := &cliflags.CommonFlags{}
 
 
 	flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
 	flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
 	flags.String([]string{"-tlscacert"}, "", "")
 	flags.String([]string{"-tlscacert"}, "", "")
@@ -256,7 +256,7 @@ func TestLoadDaemonConfigWithEmbeddedOptions(t *testing.T) {
 
 
 func TestLoadDaemonConfigWithRegistryOptions(t *testing.T) {
 func TestLoadDaemonConfigWithRegistryOptions(t *testing.T) {
 	c := &daemon.Config{}
 	c := &daemon.Config{}
-	common := &cli.CommonFlags{}
+	common := &cliflags.CommonFlags{}
 	flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
 	flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
 	c.ServiceOptions.InstallCliFlags(flags, absentFromHelp)
 	c.ServiceOptions.InstallCliFlags(flags, absentFromHelp)
 
 

+ 6 - 6
cmd/dockerd/daemon_unix_test.go

@@ -6,7 +6,7 @@ import (
 	"io/ioutil"
 	"io/ioutil"
 	"testing"
 	"testing"
 
 
-	"github.com/docker/docker/cli"
+	cliflags "github.com/docker/docker/cli/flags"
 	"github.com/docker/docker/daemon"
 	"github.com/docker/docker/daemon"
 	"github.com/docker/docker/opts"
 	"github.com/docker/docker/opts"
 	"github.com/docker/docker/pkg/mflag"
 	"github.com/docker/docker/pkg/mflag"
@@ -14,7 +14,7 @@ import (
 
 
 func TestLoadDaemonCliConfigWithDaemonFlags(t *testing.T) {
 func TestLoadDaemonCliConfigWithDaemonFlags(t *testing.T) {
 	c := &daemon.Config{}
 	c := &daemon.Config{}
-	common := &cli.CommonFlags{
+	common := &cliflags.CommonFlags{
 		Debug:    true,
 		Debug:    true,
 		LogLevel: "info",
 		LogLevel: "info",
 	}
 	}
@@ -61,7 +61,7 @@ func TestLoadDaemonCliConfigWithDaemonFlags(t *testing.T) {
 
 
 func TestLoadDaemonConfigWithNetwork(t *testing.T) {
 func TestLoadDaemonConfigWithNetwork(t *testing.T) {
 	c := &daemon.Config{}
 	c := &daemon.Config{}
-	common := &cli.CommonFlags{}
+	common := &cliflags.CommonFlags{}
 	flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
 	flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
 	flags.String([]string{"-bip"}, "", "")
 	flags.String([]string{"-bip"}, "", "")
 	flags.String([]string{"-ip"}, "", "")
 	flags.String([]string{"-ip"}, "", "")
@@ -92,7 +92,7 @@ func TestLoadDaemonConfigWithNetwork(t *testing.T) {
 
 
 func TestLoadDaemonConfigWithMapOptions(t *testing.T) {
 func TestLoadDaemonConfigWithMapOptions(t *testing.T) {
 	c := &daemon.Config{}
 	c := &daemon.Config{}
-	common := &cli.CommonFlags{}
+	common := &cliflags.CommonFlags{}
 	flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
 	flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
 
 
 	flags.Var(opts.NewNamedMapOpts("cluster-store-opts", c.ClusterOpts, nil), []string{"-cluster-store-opt"}, "")
 	flags.Var(opts.NewNamedMapOpts("cluster-store-opts", c.ClusterOpts, nil), []string{"-cluster-store-opt"}, "")
@@ -136,7 +136,7 @@ func TestLoadDaemonConfigWithMapOptions(t *testing.T) {
 
 
 func TestLoadDaemonConfigWithTrueDefaultValues(t *testing.T) {
 func TestLoadDaemonConfigWithTrueDefaultValues(t *testing.T) {
 	c := &daemon.Config{}
 	c := &daemon.Config{}
-	common := &cli.CommonFlags{}
+	common := &cliflags.CommonFlags{}
 	flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
 	flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
 	flags.BoolVar(&c.EnableUserlandProxy, []string{"-userland-proxy"}, true, "")
 	flags.BoolVar(&c.EnableUserlandProxy, []string{"-userland-proxy"}, true, "")
 
 
@@ -181,7 +181,7 @@ func TestLoadDaemonConfigWithTrueDefaultValues(t *testing.T) {
 
 
 func TestLoadDaemonConfigWithTrueDefaultValuesLeaveDefaults(t *testing.T) {
 func TestLoadDaemonConfigWithTrueDefaultValuesLeaveDefaults(t *testing.T) {
 	c := &daemon.Config{}
 	c := &daemon.Config{}
-	common := &cli.CommonFlags{}
+	common := &cliflags.CommonFlags{}
 	flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
 	flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
 	flags.BoolVar(&c.EnableUserlandProxy, []string{"-userland-proxy"}, true, "")
 	flags.BoolVar(&c.EnableUserlandProxy, []string{"-userland-proxy"}, true, "")