adding nicer help when missing arguments (#11858)
Signed-off-by: Jason Shepherd <jason@jasonshepherd.net>
This commit is contained in:
parent
172a4e1f5a
commit
a8c0208903
1 changed files with 11 additions and 3 deletions
|
@ -290,6 +290,7 @@ type FlagSet struct {
|
||||||
// The field is a function (not a method) that may be changed to point to
|
// The field is a function (not a method) that may be changed to point to
|
||||||
// a custom error handler.
|
// a custom error handler.
|
||||||
Usage func()
|
Usage func()
|
||||||
|
ShortUsage func()
|
||||||
|
|
||||||
name string
|
name string
|
||||||
parsed bool
|
parsed bool
|
||||||
|
@ -564,6 +565,12 @@ var Usage = func() {
|
||||||
PrintDefaults()
|
PrintDefaults()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Usage prints to standard error a usage message documenting the standard command layout
|
||||||
|
// The function is a variable that may be changed to point to a custom function.
|
||||||
|
var ShortUsage = func() {
|
||||||
|
fmt.Fprintf(CommandLine.output, "Usage of %s:\n", os.Args[0])
|
||||||
|
}
|
||||||
|
|
||||||
// FlagCount returns the number of flags that have been defined.
|
// FlagCount returns the number of flags that have been defined.
|
||||||
func (f *FlagSet) FlagCount() int { return len(sortFlags(f.formal)) }
|
func (f *FlagSet) FlagCount() int { return len(sortFlags(f.formal)) }
|
||||||
|
|
||||||
|
@ -1073,6 +1080,8 @@ func (cmd *FlagSet) ParseFlags(args []string, withHelp bool) error {
|
||||||
}
|
}
|
||||||
if str := cmd.CheckArgs(); str != "" {
|
if str := cmd.CheckArgs(); str != "" {
|
||||||
cmd.ReportError(str, withHelp)
|
cmd.ReportError(str, withHelp)
|
||||||
|
cmd.ShortUsage()
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -1085,8 +1094,7 @@ func (cmd *FlagSet) ReportError(str string, withHelp bool) {
|
||||||
str += ". See '" + os.Args[0] + " " + cmd.Name() + " --help'"
|
str += ". See '" + os.Args[0] + " " + cmd.Name() + " --help'"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Fprintf(cmd.Out(), "docker: %s\n", str)
|
fmt.Fprintf(cmd.Out(), "docker: %s.\n", str)
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parsed reports whether f.Parse has been called.
|
// Parsed reports whether f.Parse has been called.
|
||||||
|
|
Loading…
Reference in a new issue