Carry #11858
Continues 11858 by: - Making sure the exit code is always zero when we ask for help - Making sure the exit code isn't zero when we print help on error cases - Making sure both short and long usage go to the same stream (stdout vs stderr) - Making sure all docker commands support --help - Test that all cmds send --help to stdout, exit code 0, show full usage, no blank lines at end - Test that all cmds (that support it) show short usage on bad arg to stderr, no blank line at end - Test that all cmds complain about a bad option, no blank line at end - Test that docker (w/o subcmd) does the same stuff mentioned above properly Signed-off-by: Doug Davis <dug@us.ibm.com>
This commit is contained in:
parent
a8c0208903
commit
ef185a9afc
1 changed files with 10 additions and 3 deletions
|
@ -512,6 +512,12 @@ func (f *FlagSet) PrintDefaults() {
|
|||
if runtime.GOOS != "windows" && home == "/" {
|
||||
home = ""
|
||||
}
|
||||
|
||||
// Add a blank line between cmd description and list of options
|
||||
if f.FlagCount() > 0 {
|
||||
fmt.Fprintln(writer, "")
|
||||
}
|
||||
|
||||
f.VisitAll(func(flag *Flag) {
|
||||
format := " -%s=%s"
|
||||
names := []string{}
|
||||
|
@ -1074,11 +1080,12 @@ func (cmd *FlagSet) ParseFlags(args []string, withHelp bool) error {
|
|||
return err
|
||||
}
|
||||
if help != nil && *help {
|
||||
cmd.SetOutput(os.Stdout)
|
||||
cmd.Usage()
|
||||
// just in case Usage does not exit
|
||||
os.Exit(0)
|
||||
}
|
||||
if str := cmd.CheckArgs(); str != "" {
|
||||
cmd.SetOutput(os.Stderr)
|
||||
cmd.ReportError(str, withHelp)
|
||||
cmd.ShortUsage()
|
||||
os.Exit(1)
|
||||
|
@ -1089,9 +1096,9 @@ func (cmd *FlagSet) ParseFlags(args []string, withHelp bool) error {
|
|||
func (cmd *FlagSet) ReportError(str string, withHelp bool) {
|
||||
if withHelp {
|
||||
if os.Args[0] == cmd.Name() {
|
||||
str += ". See '" + os.Args[0] + " --help'"
|
||||
str += ".\nSee '" + os.Args[0] + " --help'"
|
||||
} else {
|
||||
str += ". See '" + os.Args[0] + " " + cmd.Name() + " --help'"
|
||||
str += ".\nSee '" + os.Args[0] + " " + cmd.Name() + " --help'"
|
||||
}
|
||||
}
|
||||
fmt.Fprintf(cmd.Out(), "docker: %s.\n", str)
|
||||
|
|
Loading…
Reference in a new issue