mirror of https://github.com/docker/docs.git
Merge pull request #689 from dotcloud/help_command-fix
- Runtime: bring Error: Command not found: <command>
This commit is contained in:
commit
064101d82e
1
api.go
1
api.go
|
@ -662,6 +662,5 @@ func ListenAndServe(addr string, srv *Server, logging bool) error {
|
||||||
r.Path(localRoute).Methods(localMethod).HandlerFunc(f)
|
r.Path(localRoute).Methods(localMethod).HandlerFunc(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return http.ListenAndServe(addr, r)
|
return http.ListenAndServe(addr, r)
|
||||||
}
|
}
|
||||||
|
|
22
commands.go
22
commands.go
|
@ -30,15 +30,19 @@ var (
|
||||||
GIT_COMMIT string
|
GIT_COMMIT string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (cli *DockerCli) getMethod(name string) (reflect.Method, bool) {
|
||||||
|
methodName := "Cmd" + strings.ToUpper(name[:1]) + strings.ToLower(name[1:])
|
||||||
|
return reflect.TypeOf(cli).MethodByName(methodName)
|
||||||
|
}
|
||||||
|
|
||||||
func ParseCommands(addr string, port int, args ...string) error {
|
func ParseCommands(addr string, port int, args ...string) error {
|
||||||
cli := NewDockerCli(addr, port)
|
cli := NewDockerCli(addr, port)
|
||||||
|
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
methodName := "Cmd" + strings.ToUpper(args[0][:1]) + strings.ToLower(args[0][1:])
|
method, exists := cli.getMethod(args[0])
|
||||||
method, exists := reflect.TypeOf(cli).MethodByName(methodName)
|
|
||||||
if !exists {
|
if !exists {
|
||||||
fmt.Println("Error: Command not found:", args[0])
|
fmt.Println("Error: Command not found:", args[0])
|
||||||
return cli.CmdHelp(args...)
|
return cli.CmdHelp(args[1:]...)
|
||||||
}
|
}
|
||||||
ret := method.Func.CallSlice([]reflect.Value{
|
ret := method.Func.CallSlice([]reflect.Value{
|
||||||
reflect.ValueOf(cli),
|
reflect.ValueOf(cli),
|
||||||
|
@ -53,6 +57,18 @@ func ParseCommands(addr string, port int, args ...string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *DockerCli) CmdHelp(args ...string) error {
|
func (cli *DockerCli) CmdHelp(args ...string) error {
|
||||||
|
if len(args) > 0 {
|
||||||
|
method, exists := cli.getMethod(args[0])
|
||||||
|
if !exists {
|
||||||
|
fmt.Println("Error: Command not found:", args[0])
|
||||||
|
} else {
|
||||||
|
method.Func.CallSlice([]reflect.Value{
|
||||||
|
reflect.ValueOf(cli),
|
||||||
|
reflect.ValueOf([]string{"--help"}),
|
||||||
|
})[0].Interface()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
help := fmt.Sprintf("Usage: docker [OPTIONS] COMMAND [arg...]\n -H=\"%s:%d\": Host:port to bind/connect to\n\nA self-sufficient runtime for linux containers.\n\nCommands:\n", cli.addr, cli.port)
|
help := fmt.Sprintf("Usage: docker [OPTIONS] COMMAND [arg...]\n -H=\"%s:%d\": Host:port to bind/connect to\n\nA self-sufficient runtime for linux containers.\n\nCommands:\n", cli.addr, cli.port)
|
||||||
for cmd, description := range map[string]string{
|
for cmd, description := range map[string]string{
|
||||||
"attach": "Attach to a running container",
|
"attach": "Attach to a running container",
|
||||||
|
|
Loading…
Reference in New Issue