mirror of https://github.com/docker/cli.git
Merge pull request #22372 from dnephin/cli_cleanup
Reorganize client and cli packages
This commit is contained in:
commit
5de3b105a8
38
client.go
38
client.go
|
@ -1,38 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
"github.com/docker/docker/cli"
|
|
||||||
cliflags "github.com/docker/docker/cli/flags"
|
|
||||||
"github.com/docker/docker/cliconfig"
|
|
||||||
flag "github.com/docker/docker/pkg/mflag"
|
|
||||||
"github.com/docker/docker/utils"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
commonFlags = cliflags.InitCommonFlags()
|
|
||||||
clientFlags = &cli.ClientFlags{FlagSet: new(flag.FlagSet), Common: commonFlags}
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
|
|
||||||
client := clientFlags.FlagSet
|
|
||||||
client.StringVar(&clientFlags.ConfigDir, []string{"-config"}, cliconfig.ConfigDir(), "Location of client config files")
|
|
||||||
|
|
||||||
clientFlags.PostParse = func() {
|
|
||||||
clientFlags.Common.PostParse()
|
|
||||||
|
|
||||||
if clientFlags.ConfigDir != "" {
|
|
||||||
cliconfig.SetConfigDir(clientFlags.ConfigDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
if clientFlags.Common.TrustKey == "" {
|
|
||||||
clientFlags.Common.TrustKey = filepath.Join(cliconfig.ConfigDir(), cliflags.DefaultTrustKeyFile)
|
|
||||||
}
|
|
||||||
|
|
||||||
if clientFlags.Common.Debug {
|
|
||||||
utils.EnableDebug()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
34
docker.go
34
docker.go
|
@ -3,16 +3,26 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/docker/api/client"
|
"github.com/docker/docker/api/client"
|
||||||
"github.com/docker/docker/cli"
|
"github.com/docker/docker/cli"
|
||||||
|
cliflags "github.com/docker/docker/cli/flags"
|
||||||
|
"github.com/docker/docker/cliconfig"
|
||||||
"github.com/docker/docker/dockerversion"
|
"github.com/docker/docker/dockerversion"
|
||||||
flag "github.com/docker/docker/pkg/mflag"
|
flag "github.com/docker/docker/pkg/mflag"
|
||||||
"github.com/docker/docker/pkg/term"
|
"github.com/docker/docker/pkg/term"
|
||||||
"github.com/docker/docker/utils"
|
"github.com/docker/docker/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
commonFlags = cliflags.InitCommonFlags()
|
||||||
|
clientFlags = initClientFlags(commonFlags)
|
||||||
|
flHelp = flag.Bool([]string{"h", "-help"}, false, "Print usage")
|
||||||
|
flVersion = flag.Bool([]string{"v", "-version"}, false, "Print version information and quit")
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Set terminal emulation based on platform as required.
|
// Set terminal emulation based on platform as required.
|
||||||
stdin, stdout, stderr := term.StdStreams()
|
stdin, stdout, stderr := term.StdStreams()
|
||||||
|
@ -30,6 +40,7 @@ func main() {
|
||||||
|
|
||||||
help := "\nCommands:\n"
|
help := "\nCommands:\n"
|
||||||
|
|
||||||
|
dockerCommands := sortCommands(cli.DockerCommandUsage)
|
||||||
for _, cmd := range dockerCommands {
|
for _, cmd := range dockerCommands {
|
||||||
help += fmt.Sprintf(" %-10.10s%s\n", cmd.Name, cmd.Description)
|
help += fmt.Sprintf(" %-10.10s%s\n", cmd.Name, cmd.Description)
|
||||||
}
|
}
|
||||||
|
@ -75,3 +86,26 @@ func showVersion() {
|
||||||
fmt.Printf("Docker version %s, build %s\n", dockerversion.Version, dockerversion.GitCommit)
|
fmt.Printf("Docker version %s, build %s\n", dockerversion.Version, dockerversion.GitCommit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func initClientFlags(commonFlags *cliflags.CommonFlags) *cliflags.ClientFlags {
|
||||||
|
clientFlags := &cliflags.ClientFlags{FlagSet: new(flag.FlagSet), Common: commonFlags}
|
||||||
|
client := clientFlags.FlagSet
|
||||||
|
client.StringVar(&clientFlags.ConfigDir, []string{"-config"}, cliconfig.ConfigDir(), "Location of client config files")
|
||||||
|
|
||||||
|
clientFlags.PostParse = func() {
|
||||||
|
clientFlags.Common.PostParse()
|
||||||
|
|
||||||
|
if clientFlags.ConfigDir != "" {
|
||||||
|
cliconfig.SetConfigDir(clientFlags.ConfigDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
if clientFlags.Common.TrustKey == "" {
|
||||||
|
clientFlags.Common.TrustKey = filepath.Join(cliconfig.ConfigDir(), cliflags.DefaultTrustKeyFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
if clientFlags.Common.Debug {
|
||||||
|
utils.EnableDebug()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return clientFlags
|
||||||
|
}
|
||||||
|
|
|
@ -4,12 +4,6 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/docker/docker/cli"
|
"github.com/docker/docker/cli"
|
||||||
flag "github.com/docker/docker/pkg/mflag"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
flHelp = flag.Bool([]string{"h", "-help"}, false, "Print usage")
|
|
||||||
flVersion = flag.Bool([]string{"v", "-version"}, false, "Print version information and quit")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type byName []cli.Command
|
type byName []cli.Command
|
||||||
|
@ -18,13 +12,11 @@ func (a byName) Len() int { return len(a) }
|
||||||
func (a byName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
func (a byName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||||
func (a byName) Less(i, j int) bool { return a[i].Name < a[j].Name }
|
func (a byName) Less(i, j int) bool { return a[i].Name < a[j].Name }
|
||||||
|
|
||||||
var dockerCommands []cli.Command
|
|
||||||
|
|
||||||
// TODO(tiborvass): do not show 'daemon' on client-only binaries
|
// TODO(tiborvass): do not show 'daemon' on client-only binaries
|
||||||
|
|
||||||
func init() {
|
func sortCommands(commands []cli.Command) []cli.Command {
|
||||||
for _, cmd := range cli.DockerCommands {
|
dockerCommands := make([]cli.Command, len(commands))
|
||||||
dockerCommands = append(dockerCommands, cmd)
|
copy(dockerCommands, commands)
|
||||||
}
|
|
||||||
sort.Sort(byName(dockerCommands))
|
sort.Sort(byName(dockerCommands))
|
||||||
|
return dockerCommands
|
||||||
}
|
}
|
|
@ -3,11 +3,13 @@ package main
|
||||||
import (
|
import (
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/docker/docker/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Tests if the subcommands of docker are sorted
|
// Tests if the subcommands of docker are sorted
|
||||||
func TestDockerSubcommandsAreSorted(t *testing.T) {
|
func TestDockerSubcommandsAreSorted(t *testing.T) {
|
||||||
if !sort.IsSorted(byName(dockerCommands)) {
|
if !sort.IsSorted(byName(cli.DockerCommandUsage)) {
|
||||||
t.Fatal("Docker subcommands are not in sorted order")
|
t.Fatal("Docker subcommands are not in sorted order")
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue