diff --git a/commands.go b/commands.go index e5deafceda..1f2c3650d7 100644 --- a/commands.go +++ b/commands.go @@ -814,14 +814,16 @@ func (srv *Server) CmdTag(stdin io.ReadCloser, stdout io.Writer, args ...string) } func (srv *Server) CmdRun(stdin io.ReadCloser, stdout io.Writer, args ...string) error { - config, err := ParseRun(args) + config, err := ParseRun(args, stdout) if err != nil { return err } if config.Image == "" { + fmt.Fprintln(stdout, "Error: Image not specified") return fmt.Errorf("Image not specified") } if len(config.Cmd) == 0 { + fmt.Fprintln(stdout, "Error: Command not specified") return fmt.Errorf("Command not specified") } // Create new container diff --git a/container.go b/container.go index d062262dfe..785b351c22 100644 --- a/container.go +++ b/container.go @@ -3,8 +3,8 @@ package docker import ( "encoding/json" "errors" - "flag" "fmt" + "github.com/dotcloud/docker/rcli" "github.com/kr/pty" "io" "io/ioutil" @@ -60,9 +60,12 @@ type Config struct { Image string // Name of the image as it was passed by the operator (eg. could be symbolic) } -func ParseRun(args []string) (*Config, error) { - cmd := flag.NewFlagSet("", flag.ContinueOnError) - cmd.SetOutput(ioutil.Discard) +func ParseRun(args []string, stdout io.Writer) (*Config, error) { + cmd := rcli.Subcmd(stdout, "run", "[OPTIONS] IMAGE COMMAND [ARG...]", "Run a command in a new container") + if len(args) > 0 && args[0] != "--help" { + cmd.SetOutput(ioutil.Discard) + } + fl_user := cmd.String("u", "", "Username or UID") fl_detach := cmd.Bool("d", false, "Detached mode: leave the container running in the background") fl_stdin := cmd.Bool("i", false, "Keep stdin open even if not attached")