mirror of https://github.com/docker/docs.git
use less reflection in command line method invocation
This commit is contained in:
parent
8240e37b87
commit
181b9baddd
|
@ -56,13 +56,13 @@ type APIContainers struct {
|
||||||
|
|
||||||
func (self *APIContainers) ToLegacy() APIContainersOld {
|
func (self *APIContainers) ToLegacy() APIContainersOld {
|
||||||
return APIContainersOld{
|
return APIContainersOld{
|
||||||
ID: self.ID,
|
ID: self.ID,
|
||||||
Image: self.Image,
|
Image: self.Image,
|
||||||
Command: self.Command,
|
Command: self.Command,
|
||||||
Created: self.Created,
|
Created: self.Created,
|
||||||
Status: self.Status,
|
Status: self.Status,
|
||||||
Ports: displayablePorts(self.Ports),
|
Ports: displayablePorts(self.Ports),
|
||||||
SizeRw: self.SizeRw,
|
SizeRw: self.SizeRw,
|
||||||
SizeRootFs: self.SizeRootFs,
|
SizeRootFs: self.SizeRootFs,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -566,7 +566,6 @@ func TestPostCommit(t *testing.T) {
|
||||||
|
|
||||||
srv := &Server{runtime: runtime}
|
srv := &Server{runtime: runtime}
|
||||||
|
|
||||||
|
|
||||||
// Create a container and remove a file
|
// Create a container and remove a file
|
||||||
container, err := runtime.Create(
|
container, err := runtime.Create(
|
||||||
&Config{
|
&Config{
|
||||||
|
|
22
commands.go
22
commands.go
|
@ -36,9 +36,13 @@ var (
|
||||||
VERSION string
|
VERSION string
|
||||||
)
|
)
|
||||||
|
|
||||||
func (cli *DockerCli) getMethod(name string) (reflect.Method, bool) {
|
func (cli *DockerCli) getMethod(name string) (func(...string) error, bool) {
|
||||||
methodName := "Cmd" + strings.ToUpper(name[:1]) + strings.ToLower(name[1:])
|
methodName := "Cmd" + strings.ToUpper(name[:1]) + strings.ToLower(name[1:])
|
||||||
return reflect.TypeOf(cli).MethodByName(methodName)
|
method := reflect.ValueOf(cli).MethodByName(methodName)
|
||||||
|
if !method.IsValid() {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
return method.Interface().(func(...string) error), true
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseCommands(proto, addr string, args ...string) error {
|
func ParseCommands(proto, addr string, args ...string) error {
|
||||||
|
@ -50,14 +54,7 @@ func ParseCommands(proto, addr string, args ...string) error {
|
||||||
fmt.Println("Error: Command not found:", args[0])
|
fmt.Println("Error: Command not found:", args[0])
|
||||||
return cli.CmdHelp(args[1:]...)
|
return cli.CmdHelp(args[1:]...)
|
||||||
}
|
}
|
||||||
ret := method.Func.CallSlice([]reflect.Value{
|
return method(args[1:]...)
|
||||||
reflect.ValueOf(cli),
|
|
||||||
reflect.ValueOf(args[1:]),
|
|
||||||
})[0].Interface()
|
|
||||||
if ret == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return ret.(error)
|
|
||||||
}
|
}
|
||||||
return cli.CmdHelp(args...)
|
return cli.CmdHelp(args...)
|
||||||
}
|
}
|
||||||
|
@ -68,10 +65,7 @@ func (cli *DockerCli) CmdHelp(args ...string) error {
|
||||||
if !exists {
|
if !exists {
|
||||||
fmt.Fprintf(cli.err, "Error: Command not found: %s\n", args[0])
|
fmt.Fprintf(cli.err, "Error: Command not found: %s\n", args[0])
|
||||||
} else {
|
} else {
|
||||||
method.Func.CallSlice([]reflect.Value{
|
method("--help")
|
||||||
reflect.ValueOf(cli),
|
|
||||||
reflect.ValueOf([]string{"--help"}),
|
|
||||||
})[0].Interface()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue