Skip to content

Commit

Permalink
Merge pull request moby#10008 from rhatdan/help
Browse files Browse the repository at this point in the history
Fix docker run/create not printing error messages
  • Loading branch information
Jessie Frazelle committed Jan 13, 2015
2 parents 9f2c486 + 12a7e78 commit 6e5c5d3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions api/client/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -2164,7 +2164,7 @@ func (cli *DockerCli) CmdCreate(args ...string) error {

config, hostConfig, cmd, err := runconfig.Parse(cmd, args)
if err != nil {
return &utils.StatusError{StatusCode: 1}
utils.ReportError(cmd, err.Error(), true)
}
if config.Image == "" {
cmd.Usage()
Expand Down Expand Up @@ -2201,7 +2201,7 @@ func (cli *DockerCli) CmdRun(args ...string) error {
config, hostConfig, cmd, err := runconfig.Parse(cmd, args)
// just in case the Parse does not exit
if err != nil {
return &utils.StatusError{StatusCode: 1}
utils.ReportError(cmd, err.Error(), true)
}
if config.Image == "" {
cmd.Usage()
Expand Down
22 changes: 13 additions & 9 deletions utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,19 @@ func ParseFlags(cmd *flag.FlagSet, args []string, withHelp bool) error {
os.Exit(0)
}
if str := cmd.CheckArgs(); str != "" {
if withHelp {
if os.Args[0] == cmd.Name() {
str += ". See '" + os.Args[0] + " --help'"
} else {
str += ". See '" + os.Args[0] + " " + cmd.Name() + " --help'"
}
}
fmt.Fprintf(cmd.Out(), "docker: %s.\n", str)
os.Exit(1)
ReportError(cmd, str, withHelp)
}
return nil
}

func ReportError(cmd *flag.FlagSet, str string, withHelp bool) {
if withHelp {
if os.Args[0] == cmd.Name() {
str += ". See '" + os.Args[0] + " --help'"
} else {
str += ". See '" + os.Args[0] + " " + cmd.Name() + " --help'"
}
}
fmt.Fprintf(cmd.Out(), "docker: %s.\n", str)
os.Exit(1)
}

0 comments on commit 6e5c5d3

Please sign in to comment.