bring Error: Command not found: <command>
Usage: docker COMMAND [arg...] A self-sufficient runtime for linux containers. Commands: attach Attach to a running container insert Insert a file in an image login Register or Login to the docker registry server export Stream the contents of a container as a tar archive diff Inspect changes on a container's filesystem logs Fetch the logs of a container pull Pull an image or a repository from the docker registry server restart Restart a running container build Build a container from Dockerfile or via stdin history Show the history of an image kill Kill a running container rmi Remove an image start Start a stopped container tag Tag an image into a repository commit Create a new image from a container's changes import Create a new filesystem image from the contents of a tarball ps List containers rm Remove a container run Run a command in a new container wait Block until a container stops, then print its exit code images List images port Lookup the public-facing port which is NAT-ed to PRIVATE_PORT info Display system-wide information inspect Return low-level information on a container push Push an image or a repository to the docker registry server search Search for an image in the docker index stop Stop a running container version Show the docker version information back
This commit is contained in:
parent
422edd513a
commit
31c98bdaaf
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(args ...string) error {
|
func ParseCommands(args ...string) error {
|
||||||
cli := NewDockerCli("0.0.0.0", 4243)
|
cli := NewDockerCli("0.0.0.0", 4243)
|
||||||
|
|
||||||
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(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 := "Usage: docker COMMAND [arg...]\n\nA self-sufficient runtime for linux containers.\n\nCommands:\n"
|
help := "Usage: docker COMMAND [arg...]\n\nA self-sufficient runtime for linux containers.\n\nCommands:\n"
|
||||||
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