Browse code

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 authored on 2016/04/22 06:51:28
Showing 10 changed files
... ...
@@ -9,7 +9,7 @@ import (
9 9
 	"runtime"
10 10
 
11 11
 	"github.com/docker/docker/api"
12
-	"github.com/docker/docker/cli"
12
+	cliflags "github.com/docker/docker/cli/flags"
13 13
 	"github.com/docker/docker/cliconfig"
14 14
 	"github.com/docker/docker/cliconfig/credentials"
15 15
 	"github.com/docker/docker/dockerversion"
... ...
@@ -112,7 +112,7 @@ func (cli *DockerCli) restoreTerminal(in io.Closer) error {
112 112
 // The key file, protocol (i.e. unix) and address are passed in as strings, along with the tls.Config. If the tls.Config
113 113
 // is set the client scheme will be set to https.
114 114
 // The client will be given a 32-second timeout (see https://github.com/docker/docker/pull/8035).
115
-func NewDockerCli(in io.ReadCloser, out, err io.Writer, clientFlags *cli.ClientFlags) *DockerCli {
115
+func NewDockerCli(in io.ReadCloser, out, err io.Writer, clientFlags *cliflags.ClientFlags) *DockerCli {
116 116
 	cli := &DockerCli{
117 117
 		in:      in,
118 118
 		out:     out,
119 119
deleted file mode 100644
... ...
@@ -1,12 +0,0 @@
1
-package cli
2
-
3
-import flag "github.com/docker/docker/pkg/mflag"
4
-
5
-// ClientFlags represents flags for the docker client.
6
-type ClientFlags struct {
7
-	FlagSet   *flag.FlagSet
8
-	Common    *CommonFlags
9
-	PostParse func()
10
-
11
-	ConfigDir string
12
-}
13 1
deleted file mode 100644
... ...
@@ -1,80 +0,0 @@
1
-package cli
2
-
3
-import (
4
-	flag "github.com/docker/docker/pkg/mflag"
5
-	"github.com/docker/go-connections/tlsconfig"
6
-)
7
-
8
-// CommonFlags represents flags that are common to both the client and the daemon.
9
-type CommonFlags struct {
10
-	FlagSet   *flag.FlagSet
11
-	PostParse func()
12
-
13
-	Debug      bool
14
-	Hosts      []string
15
-	LogLevel   string
16
-	TLS        bool
17
-	TLSVerify  bool
18
-	TLSOptions *tlsconfig.Options
19
-	TrustKey   string
20
-}
21
-
22
-// Command is the struct containing the command name and description
23
-type Command struct {
24
-	Name        string
25
-	Description string
26
-}
27
-
28
-var dockerCommands = []Command{
29
-	{"attach", "Attach to a running container"},
30
-	{"build", "Build an image from a Dockerfile"},
31
-	{"commit", "Create a new image from a container's changes"},
32
-	{"cp", "Copy files/folders between a container and the local filesystem"},
33
-	{"create", "Create a new container"},
34
-	{"diff", "Inspect changes on a container's filesystem"},
35
-	{"events", "Get real time events from the server"},
36
-	{"exec", "Run a command in a running container"},
37
-	{"export", "Export a container's filesystem as a tar archive"},
38
-	{"history", "Show the history of an image"},
39
-	{"images", "List images"},
40
-	{"import", "Import the contents from a tarball to create a filesystem image"},
41
-	{"info", "Display system-wide information"},
42
-	{"inspect", "Return low-level information on a container or image"},
43
-	{"kill", "Kill a running container"},
44
-	{"load", "Load an image from a tar archive or STDIN"},
45
-	{"login", "Log in to a Docker registry"},
46
-	{"logout", "Log out from a Docker registry"},
47
-	{"logs", "Fetch the logs of a container"},
48
-	{"network", "Manage Docker networks"},
49
-	{"pause", "Pause all processes within a container"},
50
-	{"port", "List port mappings or a specific mapping for the CONTAINER"},
51
-	{"ps", "List containers"},
52
-	{"pull", "Pull an image or a repository from a registry"},
53
-	{"push", "Push an image or a repository to a registry"},
54
-	{"rename", "Rename a container"},
55
-	{"restart", "Restart a container"},
56
-	{"rm", "Remove one or more containers"},
57
-	{"rmi", "Remove one or more images"},
58
-	{"run", "Run a command in a new container"},
59
-	{"save", "Save one or more images to a tar archive"},
60
-	{"search", "Search the Docker Hub for images"},
61
-	{"start", "Start one or more stopped containers"},
62
-	{"stats", "Display a live stream of container(s) resource usage statistics"},
63
-	{"stop", "Stop a running container"},
64
-	{"tag", "Tag an image into a repository"},
65
-	{"top", "Display the running processes of a container"},
66
-	{"unpause", "Unpause all processes within a container"},
67
-	{"update", "Update configuration of one or more containers"},
68
-	{"version", "Show the Docker version information"},
69
-	{"volume", "Manage Docker volumes"},
70
-	{"wait", "Block until a container stops, then print its exit code"},
71
-}
72
-
73
-// DockerCommands stores all the docker command
74
-var DockerCommands = make(map[string]Command)
75
-
76
-func init() {
77
-	for _, cmd := range dockerCommands {
78
-		DockerCommands[cmd.Name] = cmd
79
-	}
80
-}
81 1
new file mode 100644
... ...
@@ -0,0 +1,12 @@
0
+package flags
1
+
2
+import flag "github.com/docker/docker/pkg/mflag"
3
+
4
+// ClientFlags represents flags for the docker client.
5
+type ClientFlags struct {
6
+	FlagSet   *flag.FlagSet
7
+	Common    *CommonFlags
8
+	PostParse func()
9
+
10
+	ConfigDir string
11
+}
... ...
@@ -6,7 +6,6 @@ import (
6 6
 	"path/filepath"
7 7
 
8 8
 	"github.com/Sirupsen/logrus"
9
-	"github.com/docker/docker/cli"
10 9
 	"github.com/docker/docker/cliconfig"
11 10
 	"github.com/docker/docker/opts"
12 11
 	flag "github.com/docker/docker/pkg/mflag"
... ...
@@ -31,9 +30,23 @@ var (
31 31
 	dockerTLSVerify = os.Getenv("DOCKER_TLS_VERIFY") != ""
32 32
 )
33 33
 
34
+// CommonFlags are flags common to both the client and the daemon.
35
+type CommonFlags struct {
36
+	FlagSet   *flag.FlagSet
37
+	PostParse func()
38
+
39
+	Debug      bool
40
+	Hosts      []string
41
+	LogLevel   string
42
+	TLS        bool
43
+	TLSVerify  bool
44
+	TLSOptions *tlsconfig.Options
45
+	TrustKey   string
46
+}
47
+
34 48
 // InitCommonFlags initializes flags common to both client and daemon
35
-func InitCommonFlags() *cli.CommonFlags {
36
-	var commonFlags = &cli.CommonFlags{FlagSet: new(flag.FlagSet)}
49
+func InitCommonFlags() *CommonFlags {
50
+	var commonFlags = &CommonFlags{FlagSet: new(flag.FlagSet)}
37 51
 
38 52
 	if dockerCertPath == "" {
39 53
 		dockerCertPath = cliconfig.ConfigDir()
... ...
@@ -60,7 +73,7 @@ func InitCommonFlags() *cli.CommonFlags {
60 60
 	return commonFlags
61 61
 }
62 62
 
63
-func postParseCommon(commonFlags *cli.CommonFlags) {
63
+func postParseCommon(commonFlags *CommonFlags) {
64 64
 	cmd := commonFlags.FlagSet
65 65
 
66 66
 	SetDaemonLogLevel(commonFlags.LogLevel)
67 67
new file mode 100644
... ...
@@ -0,0 +1,61 @@
0
+package cli
1
+
2
+// Command is the struct containing the command name and description
3
+type Command struct {
4
+	Name        string
5
+	Description string
6
+}
7
+
8
+var dockerCommands = []Command{
9
+	{"attach", "Attach to a running container"},
10
+	{"build", "Build an image from a Dockerfile"},
11
+	{"commit", "Create a new image from a container's changes"},
12
+	{"cp", "Copy files/folders between a container and the local filesystem"},
13
+	{"create", "Create a new container"},
14
+	{"diff", "Inspect changes on a container's filesystem"},
15
+	{"events", "Get real time events from the server"},
16
+	{"exec", "Run a command in a running container"},
17
+	{"export", "Export a container's filesystem as a tar archive"},
18
+	{"history", "Show the history of an image"},
19
+	{"images", "List images"},
20
+	{"import", "Import the contents from a tarball to create a filesystem image"},
21
+	{"info", "Display system-wide information"},
22
+	{"inspect", "Return low-level information on a container or image"},
23
+	{"kill", "Kill a running container"},
24
+	{"load", "Load an image from a tar archive or STDIN"},
25
+	{"login", "Log in to a Docker registry"},
26
+	{"logout", "Log out from a Docker registry"},
27
+	{"logs", "Fetch the logs of a container"},
28
+	{"network", "Manage Docker networks"},
29
+	{"pause", "Pause all processes within a container"},
30
+	{"port", "List port mappings or a specific mapping for the CONTAINER"},
31
+	{"ps", "List containers"},
32
+	{"pull", "Pull an image or a repository from a registry"},
33
+	{"push", "Push an image or a repository to a registry"},
34
+	{"rename", "Rename a container"},
35
+	{"restart", "Restart a container"},
36
+	{"rm", "Remove one or more containers"},
37
+	{"rmi", "Remove one or more images"},
38
+	{"run", "Run a command in a new container"},
39
+	{"save", "Save one or more images to a tar archive"},
40
+	{"search", "Search the Docker Hub for images"},
41
+	{"start", "Start one or more stopped containers"},
42
+	{"stats", "Display a live stream of container(s) resource usage statistics"},
43
+	{"stop", "Stop a running container"},
44
+	{"tag", "Tag an image into a repository"},
45
+	{"top", "Display the running processes of a container"},
46
+	{"unpause", "Unpause all processes within a container"},
47
+	{"update", "Update configuration of one or more containers"},
48
+	{"version", "Show the Docker version information"},
49
+	{"volume", "Manage Docker volumes"},
50
+	{"wait", "Block until a container stops, then print its exit code"},
51
+}
52
+
53
+// DockerCommands stores all the docker command
54
+var DockerCommands = make(map[string]Command)
55
+
56
+func init() {
57
+	for _, cmd := range dockerCommands {
58
+		DockerCommands[cmd.Name] = cmd
59
+	}
60
+}
... ...
@@ -3,7 +3,6 @@ package main
3 3
 import (
4 4
 	"path/filepath"
5 5
 
6
-	"github.com/docker/docker/cli"
7 6
 	cliflags "github.com/docker/docker/cli/flags"
8 7
 	"github.com/docker/docker/cliconfig"
9 8
 	flag "github.com/docker/docker/pkg/mflag"
... ...
@@ -12,7 +11,7 @@ import (
12 12
 
13 13
 var (
14 14
 	commonFlags = cliflags.InitCommonFlags()
15
-	clientFlags = &cli.ClientFlags{FlagSet: new(flag.FlagSet), Common: commonFlags}
15
+	clientFlags = &cliflags.ClientFlags{FlagSet: new(flag.FlagSet), Common: commonFlags}
16 16
 )
17 17
 
18 18
 func init() {
... ...
@@ -23,7 +23,6 @@ import (
23 23
 	systemrouter "github.com/docker/docker/api/server/router/system"
24 24
 	"github.com/docker/docker/api/server/router/volume"
25 25
 	"github.com/docker/docker/builder/dockerfile"
26
-	"github.com/docker/docker/cli"
27 26
 	cliflags "github.com/docker/docker/cli/flags"
28 27
 	"github.com/docker/docker/cliconfig"
29 28
 	"github.com/docker/docker/daemon"
... ...
@@ -51,7 +50,7 @@ const (
51 51
 // DaemonCli represents the daemon CLI.
52 52
 type DaemonCli struct {
53 53
 	*daemon.Config
54
-	commonFlags *cli.CommonFlags
54
+	commonFlags *cliflags.CommonFlags
55 55
 	configFile  *string
56 56
 }
57 57
 
... ...
@@ -345,7 +344,7 @@ func shutdownDaemon(d *daemon.Daemon, timeout time.Duration) {
345 345
 	}
346 346
 }
347 347
 
348
-func loadDaemonCliConfig(config *daemon.Config, flags *flag.FlagSet, commonConfig *cli.CommonFlags, configFile string) (*daemon.Config, error) {
348
+func loadDaemonCliConfig(config *daemon.Config, flags *flag.FlagSet, commonConfig *cliflags.CommonFlags, configFile string) (*daemon.Config, error) {
349 349
 	config.Debug = commonConfig.Debug
350 350
 	config.Hosts = commonConfig.Hosts
351 351
 	config.LogLevel = commonConfig.LogLevel
... ...
@@ -7,7 +7,7 @@ import (
7 7
 	"testing"
8 8
 
9 9
 	"github.com/Sirupsen/logrus"
10
-	"github.com/docker/docker/cli"
10
+	cliflags "github.com/docker/docker/cli/flags"
11 11
 	"github.com/docker/docker/daemon"
12 12
 	"github.com/docker/docker/opts"
13 13
 	"github.com/docker/docker/pkg/mflag"
... ...
@@ -16,7 +16,7 @@ import (
16 16
 
17 17
 func TestLoadDaemonCliConfigWithoutOverriding(t *testing.T) {
18 18
 	c := &daemon.Config{}
19
-	common := &cli.CommonFlags{
19
+	common := &cliflags.CommonFlags{
20 20
 		Debug: true,
21 21
 	}
22 22
 
... ...
@@ -35,7 +35,7 @@ func TestLoadDaemonCliConfigWithoutOverriding(t *testing.T) {
35 35
 
36 36
 func TestLoadDaemonCliConfigWithTLS(t *testing.T) {
37 37
 	c := &daemon.Config{}
38
-	common := &cli.CommonFlags{
38
+	common := &cliflags.CommonFlags{
39 39
 		TLS: true,
40 40
 		TLSOptions: &tlsconfig.Options{
41 41
 			CAFile: "/tmp/ca.pem",
... ...
@@ -57,7 +57,7 @@ func TestLoadDaemonCliConfigWithTLS(t *testing.T) {
57 57
 
58 58
 func TestLoadDaemonCliConfigWithConflicts(t *testing.T) {
59 59
 	c := &daemon.Config{}
60
-	common := &cli.CommonFlags{}
60
+	common := &cliflags.CommonFlags{}
61 61
 	f, err := ioutil.TempFile("", "docker-config-")
62 62
 	if err != nil {
63 63
 		t.Fatal(err)
... ...
@@ -93,7 +93,7 @@ func TestLoadDaemonCliConfigWithConflicts(t *testing.T) {
93 93
 
94 94
 func TestLoadDaemonCliConfigWithTLSVerify(t *testing.T) {
95 95
 	c := &daemon.Config{}
96
-	common := &cli.CommonFlags{
96
+	common := &cliflags.CommonFlags{
97 97
 		TLSOptions: &tlsconfig.Options{
98 98
 			CAFile: "/tmp/ca.pem",
99 99
 		},
... ...
@@ -126,7 +126,7 @@ func TestLoadDaemonCliConfigWithTLSVerify(t *testing.T) {
126 126
 
127 127
 func TestLoadDaemonCliConfigWithExplicitTLSVerifyFalse(t *testing.T) {
128 128
 	c := &daemon.Config{}
129
-	common := &cli.CommonFlags{
129
+	common := &cliflags.CommonFlags{
130 130
 		TLSOptions: &tlsconfig.Options{
131 131
 			CAFile: "/tmp/ca.pem",
132 132
 		},
... ...
@@ -159,7 +159,7 @@ func TestLoadDaemonCliConfigWithExplicitTLSVerifyFalse(t *testing.T) {
159 159
 
160 160
 func TestLoadDaemonCliConfigWithoutTLSVerify(t *testing.T) {
161 161
 	c := &daemon.Config{}
162
-	common := &cli.CommonFlags{
162
+	common := &cliflags.CommonFlags{
163 163
 		TLSOptions: &tlsconfig.Options{
164 164
 			CAFile: "/tmp/ca.pem",
165 165
 		},
... ...
@@ -191,7 +191,7 @@ func TestLoadDaemonCliConfigWithoutTLSVerify(t *testing.T) {
191 191
 
192 192
 func TestLoadDaemonCliConfigWithLogLevel(t *testing.T) {
193 193
 	c := &daemon.Config{}
194
-	common := &cli.CommonFlags{}
194
+	common := &cliflags.CommonFlags{}
195 195
 
196 196
 	f, err := ioutil.TempFile("", "docker-config-")
197 197
 	if err != nil {
... ...
@@ -223,7 +223,7 @@ func TestLoadDaemonCliConfigWithLogLevel(t *testing.T) {
223 223
 
224 224
 func TestLoadDaemonConfigWithEmbeddedOptions(t *testing.T) {
225 225
 	c := &daemon.Config{}
226
-	common := &cli.CommonFlags{}
226
+	common := &cliflags.CommonFlags{}
227 227
 
228 228
 	flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
229 229
 	flags.String([]string{"-tlscacert"}, "", "")
... ...
@@ -256,7 +256,7 @@ func TestLoadDaemonConfigWithEmbeddedOptions(t *testing.T) {
256 256
 
257 257
 func TestLoadDaemonConfigWithRegistryOptions(t *testing.T) {
258 258
 	c := &daemon.Config{}
259
-	common := &cli.CommonFlags{}
259
+	common := &cliflags.CommonFlags{}
260 260
 	flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
261 261
 	c.ServiceOptions.InstallCliFlags(flags, absentFromHelp)
262 262
 
... ...
@@ -6,7 +6,7 @@ import (
6 6
 	"io/ioutil"
7 7
 	"testing"
8 8
 
9
-	"github.com/docker/docker/cli"
9
+	cliflags "github.com/docker/docker/cli/flags"
10 10
 	"github.com/docker/docker/daemon"
11 11
 	"github.com/docker/docker/opts"
12 12
 	"github.com/docker/docker/pkg/mflag"
... ...
@@ -14,7 +14,7 @@ import (
14 14
 
15 15
 func TestLoadDaemonCliConfigWithDaemonFlags(t *testing.T) {
16 16
 	c := &daemon.Config{}
17
-	common := &cli.CommonFlags{
17
+	common := &cliflags.CommonFlags{
18 18
 		Debug:    true,
19 19
 		LogLevel: "info",
20 20
 	}
... ...
@@ -61,7 +61,7 @@ func TestLoadDaemonCliConfigWithDaemonFlags(t *testing.T) {
61 61
 
62 62
 func TestLoadDaemonConfigWithNetwork(t *testing.T) {
63 63
 	c := &daemon.Config{}
64
-	common := &cli.CommonFlags{}
64
+	common := &cliflags.CommonFlags{}
65 65
 	flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
66 66
 	flags.String([]string{"-bip"}, "", "")
67 67
 	flags.String([]string{"-ip"}, "", "")
... ...
@@ -92,7 +92,7 @@ func TestLoadDaemonConfigWithNetwork(t *testing.T) {
92 92
 
93 93
 func TestLoadDaemonConfigWithMapOptions(t *testing.T) {
94 94
 	c := &daemon.Config{}
95
-	common := &cli.CommonFlags{}
95
+	common := &cliflags.CommonFlags{}
96 96
 	flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
97 97
 
98 98
 	flags.Var(opts.NewNamedMapOpts("cluster-store-opts", c.ClusterOpts, nil), []string{"-cluster-store-opt"}, "")
... ...
@@ -136,7 +136,7 @@ func TestLoadDaemonConfigWithMapOptions(t *testing.T) {
136 136
 
137 137
 func TestLoadDaemonConfigWithTrueDefaultValues(t *testing.T) {
138 138
 	c := &daemon.Config{}
139
-	common := &cli.CommonFlags{}
139
+	common := &cliflags.CommonFlags{}
140 140
 	flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
141 141
 	flags.BoolVar(&c.EnableUserlandProxy, []string{"-userland-proxy"}, true, "")
142 142
 
... ...
@@ -181,7 +181,7 @@ func TestLoadDaemonConfigWithTrueDefaultValues(t *testing.T) {
181 181
 
182 182
 func TestLoadDaemonConfigWithTrueDefaultValuesLeaveDefaults(t *testing.T) {
183 183
 	c := &daemon.Config{}
184
-	common := &cli.CommonFlags{}
184
+	common := &cliflags.CommonFlags{}
185 185
 	flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
186 186
 	flags.BoolVar(&c.EnableUserlandProxy, []string{"-userland-proxy"}, true, "")
187 187