1
0
mirror of https://github.com/docker/cli.git synced 2026-01-13 18:22:35 +03: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)
Upstream-commit: 12a7e78b125afd277adb7cd099817a419f4faaa0
Component: engine
This commit is contained in:
Dan Walsh
2015-01-09 14:57:05 -05:00
parent 37a68ceed5
commit 287a9987a0
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)
if err != nil {
return &utils.StatusError{StatusCode: 1}
utils.ReportError(cmd, err.Error(), true)
}
if config.Image == "" {
cmd.Usage()
@@ -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()

View File

@@ -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)
}