Signed-off-by: Daniel Nephin <dnephin@docker.com>
| ... | ... |
@@ -6,7 +6,8 @@ type Command struct {
|
| 6 | 6 |
Description string |
| 7 | 7 |
} |
| 8 | 8 |
|
| 9 |
-var dockerCommands = []Command{
|
|
| 9 |
+// DockerCommandUsage lists the top level docker commands and their short usage |
|
| 10 |
+var DockerCommandUsage = []Command{
|
|
| 10 | 11 |
{"attach", "Attach to a running container"},
|
| 11 | 12 |
{"build", "Build an image from a Dockerfile"},
|
| 12 | 13 |
{"commit", "Create a new image from a container's changes"},
|
| ... | ... |
@@ -55,7 +56,7 @@ var dockerCommands = []Command{
|
| 55 | 55 |
var DockerCommands = make(map[string]Command) |
| 56 | 56 |
|
| 57 | 57 |
func init() {
|
| 58 |
- for _, cmd := range dockerCommands {
|
|
| 58 |
+ for _, cmd := range DockerCommandUsage {
|
|
| 59 | 59 |
DockerCommands[cmd.Name] = cmd |
| 60 | 60 |
} |
| 61 | 61 |
} |
| 62 | 62 |
deleted file mode 100644 |
| ... | ... |
@@ -1,37 +0,0 @@ |
| 1 |
-package main |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- "path/filepath" |
|
| 5 |
- |
|
| 6 |
- cliflags "github.com/docker/docker/cli/flags" |
|
| 7 |
- "github.com/docker/docker/cliconfig" |
|
| 8 |
- flag "github.com/docker/docker/pkg/mflag" |
|
| 9 |
- "github.com/docker/docker/utils" |
|
| 10 |
-) |
|
| 11 |
- |
|
| 12 |
-var ( |
|
| 13 |
- commonFlags = cliflags.InitCommonFlags() |
|
| 14 |
- clientFlags = &cliflags.ClientFlags{FlagSet: new(flag.FlagSet), Common: commonFlags}
|
|
| 15 |
-) |
|
| 16 |
- |
|
| 17 |
-func init() {
|
|
| 18 |
- |
|
| 19 |
- client := clientFlags.FlagSet |
|
| 20 |
- client.StringVar(&clientFlags.ConfigDir, []string{"-config"}, cliconfig.ConfigDir(), "Location of client config files")
|
|
| 21 |
- |
|
| 22 |
- clientFlags.PostParse = func() {
|
|
| 23 |
- clientFlags.Common.PostParse() |
|
| 24 |
- |
|
| 25 |
- if clientFlags.ConfigDir != "" {
|
|
| 26 |
- cliconfig.SetConfigDir(clientFlags.ConfigDir) |
|
| 27 |
- } |
|
| 28 |
- |
|
| 29 |
- if clientFlags.Common.TrustKey == "" {
|
|
| 30 |
- clientFlags.Common.TrustKey = filepath.Join(cliconfig.ConfigDir(), cliflags.DefaultTrustKeyFile) |
|
| 31 |
- } |
|
| 32 |
- |
|
| 33 |
- if clientFlags.Common.Debug {
|
|
| 34 |
- utils.EnableDebug() |
|
| 35 |
- } |
|
| 36 |
- } |
|
| 37 |
-} |
| 38 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,23 +0,0 @@ |
| 1 |
-package main |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- "os" |
|
| 5 |
- "testing" |
|
| 6 |
- |
|
| 7 |
- "github.com/Sirupsen/logrus" |
|
| 8 |
- "github.com/docker/docker/utils" |
|
| 9 |
-) |
|
| 10 |
- |
|
| 11 |
-func TestClientDebugEnabled(t *testing.T) {
|
|
| 12 |
- defer utils.DisableDebug() |
|
| 13 |
- |
|
| 14 |
- clientFlags.Common.FlagSet.Parse([]string{"-D"})
|
|
| 15 |
- clientFlags.PostParse() |
|
| 16 |
- |
|
| 17 |
- if os.Getenv("DEBUG") != "1" {
|
|
| 18 |
- t.Fatal("expected debug enabled, got false")
|
|
| 19 |
- } |
|
| 20 |
- if logrus.GetLevel() != logrus.DebugLevel {
|
|
| 21 |
- t.Fatalf("expected logrus debug level, got %v", logrus.GetLevel())
|
|
| 22 |
- } |
|
| 23 |
-} |
| ... | ... |
@@ -3,16 +3,26 @@ package main |
| 3 | 3 |
import ( |
| 4 | 4 |
"fmt" |
| 5 | 5 |
"os" |
| 6 |
+ "path/filepath" |
|
| 6 | 7 |
|
| 7 | 8 |
"github.com/Sirupsen/logrus" |
| 8 | 9 |
"github.com/docker/docker/api/client" |
| 9 | 10 |
"github.com/docker/docker/cli" |
| 11 |
+ cliflags "github.com/docker/docker/cli/flags" |
|
| 12 |
+ "github.com/docker/docker/cliconfig" |
|
| 10 | 13 |
"github.com/docker/docker/dockerversion" |
| 11 | 14 |
flag "github.com/docker/docker/pkg/mflag" |
| 12 | 15 |
"github.com/docker/docker/pkg/term" |
| 13 | 16 |
"github.com/docker/docker/utils" |
| 14 | 17 |
) |
| 15 | 18 |
|
| 19 |
+var ( |
|
| 20 |
+ commonFlags = cliflags.InitCommonFlags() |
|
| 21 |
+ clientFlags = initClientFlags(commonFlags) |
|
| 22 |
+ flHelp = flag.Bool([]string{"h", "-help"}, false, "Print usage")
|
|
| 23 |
+ flVersion = flag.Bool([]string{"v", "-version"}, false, "Print version information and quit")
|
|
| 24 |
+) |
|
| 25 |
+ |
|
| 16 | 26 |
func main() {
|
| 17 | 27 |
// Set terminal emulation based on platform as required. |
| 18 | 28 |
stdin, stdout, stderr := term.StdStreams() |
| ... | ... |
@@ -30,6 +40,7 @@ func main() {
|
| 30 | 30 |
|
| 31 | 31 |
help := "\nCommands:\n" |
| 32 | 32 |
|
| 33 |
+ dockerCommands := sortCommands(cli.DockerCommandUsage) |
|
| 33 | 34 |
for _, cmd := range dockerCommands {
|
| 34 | 35 |
help += fmt.Sprintf(" %-10.10s%s\n", cmd.Name, cmd.Description)
|
| 35 | 36 |
} |
| ... | ... |
@@ -75,3 +86,26 @@ func showVersion() {
|
| 75 | 75 |
fmt.Printf("Docker version %s, build %s\n", dockerversion.Version, dockerversion.GitCommit)
|
| 76 | 76 |
} |
| 77 | 77 |
} |
| 78 |
+ |
|
| 79 |
+func initClientFlags(commonFlags *cliflags.CommonFlags) *cliflags.ClientFlags {
|
|
| 80 |
+ clientFlags := &cliflags.ClientFlags{FlagSet: new(flag.FlagSet), Common: commonFlags}
|
|
| 81 |
+ client := clientFlags.FlagSet |
|
| 82 |
+ client.StringVar(&clientFlags.ConfigDir, []string{"-config"}, cliconfig.ConfigDir(), "Location of client config files")
|
|
| 83 |
+ |
|
| 84 |
+ clientFlags.PostParse = func() {
|
|
| 85 |
+ clientFlags.Common.PostParse() |
|
| 86 |
+ |
|
| 87 |
+ if clientFlags.ConfigDir != "" {
|
|
| 88 |
+ cliconfig.SetConfigDir(clientFlags.ConfigDir) |
|
| 89 |
+ } |
|
| 90 |
+ |
|
| 91 |
+ if clientFlags.Common.TrustKey == "" {
|
|
| 92 |
+ clientFlags.Common.TrustKey = filepath.Join(cliconfig.ConfigDir(), cliflags.DefaultTrustKeyFile) |
|
| 93 |
+ } |
|
| 94 |
+ |
|
| 95 |
+ if clientFlags.Common.Debug {
|
|
| 96 |
+ utils.EnableDebug() |
|
| 97 |
+ } |
|
| 98 |
+ } |
|
| 99 |
+ return clientFlags |
|
| 100 |
+} |
| 78 | 101 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,23 @@ |
| 0 |
+package main |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "os" |
|
| 4 |
+ "testing" |
|
| 5 |
+ |
|
| 6 |
+ "github.com/Sirupsen/logrus" |
|
| 7 |
+ "github.com/docker/docker/utils" |
|
| 8 |
+) |
|
| 9 |
+ |
|
| 10 |
+func TestClientDebugEnabled(t *testing.T) {
|
|
| 11 |
+ defer utils.DisableDebug() |
|
| 12 |
+ |
|
| 13 |
+ clientFlags.Common.FlagSet.Parse([]string{"-D"})
|
|
| 14 |
+ clientFlags.PostParse() |
|
| 15 |
+ |
|
| 16 |
+ if os.Getenv("DEBUG") != "1" {
|
|
| 17 |
+ t.Fatal("expected debug enabled, got false")
|
|
| 18 |
+ } |
|
| 19 |
+ if logrus.GetLevel() != logrus.DebugLevel {
|
|
| 20 |
+ t.Fatalf("expected logrus debug level, got %v", logrus.GetLevel())
|
|
| 21 |
+ } |
|
| 22 |
+} |
| 0 | 23 |
deleted file mode 100644 |
| ... | ... |
@@ -1,30 +0,0 @@ |
| 1 |
-package main |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- "sort" |
|
| 5 |
- |
|
| 6 |
- "github.com/docker/docker/cli" |
|
| 7 |
- flag "github.com/docker/docker/pkg/mflag" |
|
| 8 |
-) |
|
| 9 |
- |
|
| 10 |
-var ( |
|
| 11 |
- flHelp = flag.Bool([]string{"h", "-help"}, false, "Print usage")
|
|
| 12 |
- flVersion = flag.Bool([]string{"v", "-version"}, false, "Print version information and quit")
|
|
| 13 |
-) |
|
| 14 |
- |
|
| 15 |
-type byName []cli.Command |
|
| 16 |
- |
|
| 17 |
-func (a byName) Len() int { return len(a) }
|
|
| 18 |
-func (a byName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
|
| 19 |
-func (a byName) Less(i, j int) bool { return a[i].Name < a[j].Name }
|
|
| 20 |
- |
|
| 21 |
-var dockerCommands []cli.Command |
|
| 22 |
- |
|
| 23 |
-// TODO(tiborvass): do not show 'daemon' on client-only binaries |
|
| 24 |
- |
|
| 25 |
-func init() {
|
|
| 26 |
- for _, cmd := range cli.DockerCommands {
|
|
| 27 |
- dockerCommands = append(dockerCommands, cmd) |
|
| 28 |
- } |
|
| 29 |
- sort.Sort(byName(dockerCommands)) |
|
| 30 |
-} |
| 31 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,13 +0,0 @@ |
| 1 |
-package main |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- "sort" |
|
| 5 |
- "testing" |
|
| 6 |
-) |
|
| 7 |
- |
|
| 8 |
-// Tests if the subcommands of docker are sorted |
|
| 9 |
-func TestDockerSubcommandsAreSorted(t *testing.T) {
|
|
| 10 |
- if !sort.IsSorted(byName(dockerCommands)) {
|
|
| 11 |
- t.Fatal("Docker subcommands are not in sorted order")
|
|
| 12 |
- } |
|
| 13 |
-} |
| 14 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,22 @@ |
| 0 |
+package main |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "sort" |
|
| 4 |
+ |
|
| 5 |
+ "github.com/docker/docker/cli" |
|
| 6 |
+) |
|
| 7 |
+ |
|
| 8 |
+type byName []cli.Command |
|
| 9 |
+ |
|
| 10 |
+func (a byName) Len() int { return len(a) }
|
|
| 11 |
+func (a byName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
|
| 12 |
+func (a byName) Less(i, j int) bool { return a[i].Name < a[j].Name }
|
|
| 13 |
+ |
|
| 14 |
+// TODO(tiborvass): do not show 'daemon' on client-only binaries |
|
| 15 |
+ |
|
| 16 |
+func sortCommands(commands []cli.Command) []cli.Command {
|
|
| 17 |
+ dockerCommands := make([]cli.Command, len(commands)) |
|
| 18 |
+ copy(dockerCommands, commands) |
|
| 19 |
+ sort.Sort(byName(dockerCommands)) |
|
| 20 |
+ return dockerCommands |
|
| 21 |
+} |
| 0 | 22 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,15 @@ |
| 0 |
+package main |
|
| 1 |
+ |
|
| 2 |
+import ( |
|
| 3 |
+ "sort" |
|
| 4 |
+ "testing" |
|
| 5 |
+ |
|
| 6 |
+ "github.com/docker/docker/cli" |
|
| 7 |
+) |
|
| 8 |
+ |
|
| 9 |
+// Tests if the subcommands of docker are sorted |
|
| 10 |
+func TestDockerSubcommandsAreSorted(t *testing.T) {
|
|
| 11 |
+ if !sort.IsSorted(byName(cli.DockerCommandUsage)) {
|
|
| 12 |
+ t.Fatal("Docker subcommands are not in sorted order")
|
|
| 13 |
+ } |
|
| 14 |
+} |