1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Fix docker run/exec/create not printing error messages

If an error message happens while parsing docker run or docker exec, the message
is not being printed out.

Docker-DCO-1.1-Signed-off-by: Dan Walsh <dwalsh@redhat.com> (github: rhatdan)
This commit is contained in:
Dan Walsh 2015-01-09 14:57:05 -05:00
parent 9f2c486144
commit 12a7e78b12
2 changed files with 15 additions and 11 deletions

View file

@ -2164,7 +2164,7 @@ func (cli *DockerCli) CmdCreate(args ...string) error {
config, hostConfig, cmd, err := runconfig.Parse(cmd, args) config, hostConfig, cmd, err := runconfig.Parse(cmd, args)
if err != nil { if err != nil {
return &utils.StatusError{StatusCode: 1} utils.ReportError(cmd, err.Error(), true)
} }
if config.Image == "" { if config.Image == "" {
cmd.Usage() cmd.Usage()
@ -2201,7 +2201,7 @@ func (cli *DockerCli) CmdRun(args ...string) error {
config, hostConfig, cmd, err := runconfig.Parse(cmd, args) config, hostConfig, cmd, err := runconfig.Parse(cmd, args)
// just in case the Parse does not exit // just in case the Parse does not exit
if err != nil { if err != nil {
return &utils.StatusError{StatusCode: 1} utils.ReportError(cmd, err.Error(), true)
} }
if config.Image == "" { if config.Image == "" {
cmd.Usage() cmd.Usage()

View file

@ -27,6 +27,12 @@ func ParseFlags(cmd *flag.FlagSet, args []string, withHelp bool) error {
os.Exit(0) os.Exit(0)
} }
if str := cmd.CheckArgs(); str != "" { if str := cmd.CheckArgs(); str != "" {
ReportError(cmd, str, withHelp)
}
return nil
}
func ReportError(cmd *flag.FlagSet, str string, withHelp bool) {
if withHelp { if withHelp {
if os.Args[0] == cmd.Name() { if os.Args[0] == cmd.Name() {
str += ". See '" + os.Args[0] + " --help'" str += ". See '" + os.Args[0] + " --help'"
@ -37,5 +43,3 @@ func ParseFlags(cmd *flag.FlagSet, args []string, withHelp bool) error {
fmt.Fprintf(cmd.Out(), "docker: %s.\n", str) fmt.Fprintf(cmd.Out(), "docker: %s.\n", str)
os.Exit(1) os.Exit(1)
} }
return nil
}