Browse code

Re-enabled help for run command and added client-side error messages when arguments are missing

shin- authored on 2013/03/27 00:31:26
Showing 2 changed files
... ...
@@ -814,14 +814,16 @@ func (srv *Server) CmdTag(stdin io.ReadCloser, stdout io.Writer, args ...string)
814 814
 }
815 815
 
816 816
 func (srv *Server) CmdRun(stdin io.ReadCloser, stdout io.Writer, args ...string) error {
817
-	config, err := ParseRun(args)
817
+	config, err := ParseRun(args, stdout)
818 818
 	if err != nil {
819 819
 		return err
820 820
 	}
821 821
 	if config.Image == "" {
822
+		fmt.Fprintln(stdout, "Error: Image not specified")
822 823
 		return fmt.Errorf("Image not specified")
823 824
 	}
824 825
 	if len(config.Cmd) == 0 {
826
+		fmt.Fprintln(stdout, "Error: Command not specified")
825 827
 		return fmt.Errorf("Command not specified")
826 828
 	}
827 829
 	// Create new container
... ...
@@ -3,8 +3,8 @@ package docker
3 3
 import (
4 4
 	"encoding/json"
5 5
 	"errors"
6
-	"flag"
7 6
 	"fmt"
7
+	"github.com/dotcloud/docker/rcli"
8 8
 	"github.com/kr/pty"
9 9
 	"io"
10 10
 	"io/ioutil"
... ...
@@ -60,9 +60,12 @@ type Config struct {
60 60
 	Image      string // Name of the image as it was passed by the operator (eg. could be symbolic)
61 61
 }
62 62
 
63
-func ParseRun(args []string) (*Config, error) {
64
-	cmd := flag.NewFlagSet("", flag.ContinueOnError)
65
-	cmd.SetOutput(ioutil.Discard)
63
+func ParseRun(args []string, stdout io.Writer) (*Config, error) {
64
+	cmd := rcli.Subcmd(stdout, "run", "[OPTIONS] IMAGE COMMAND [ARG...]", "Run a command in a new container")
65
+	if len(args) > 0 && args[0] != "--help" {
66
+		cmd.SetOutput(ioutil.Discard)
67
+	}
68
+
66 69
 	fl_user := cmd.String("u", "", "Username or UID")
67 70
 	fl_detach := cmd.Bool("d", false, "Detached mode: leave the container running in the background")
68 71
 	fl_stdin := cmd.Bool("i", false, "Keep stdin open even if not attached")