Signed-off-by: Jason Shepherd <jason@jasonshepherd.net>
| ... | ... |
@@ -118,18 +118,21 @@ func (cli *DockerCli) Subcmd(name, signature, description string, exitOnError bo |
| 118 | 118 |
errorHandling = flag.ContinueOnError |
| 119 | 119 |
} |
| 120 | 120 |
flags := flag.NewFlagSet(name, errorHandling) |
| 121 |
+ if signature != "" {
|
|
| 122 |
+ signature = " " + signature |
|
| 123 |
+ } |
|
| 121 | 124 |
flags.Usage = func() {
|
| 125 |
+ flags.ShortUsage() |
|
| 126 |
+ flags.PrintDefaults() |
|
| 127 |
+ os.Exit(0) |
|
| 128 |
+ } |
|
| 129 |
+ flags.ShortUsage = func() {
|
|
| 122 | 130 |
options := "" |
| 123 |
- if signature != "" {
|
|
| 124 |
- signature = " " + signature |
|
| 125 |
- } |
|
| 126 | 131 |
if flags.FlagCountUndeprecated() > 0 {
|
| 127 | 132 |
options = " [OPTIONS]" |
| 128 | 133 |
} |
| 129 | 134 |
fmt.Fprintf(cli.out, "\nUsage: docker %s%s%s\n\n%s\n\n", name, options, signature, description) |
| 130 | 135 |
flags.SetOutput(cli.out) |
| 131 |
- flags.PrintDefaults() |
|
| 132 |
- os.Exit(0) |
|
| 133 | 136 |
} |
| 134 | 137 |
return flags |
| 135 | 138 |
} |
| ... | ... |
@@ -289,7 +289,8 @@ type FlagSet struct {
|
| 289 | 289 |
// Usage is the function called when an error occurs while parsing flags. |
| 290 | 290 |
// The field is a function (not a method) that may be changed to point to |
| 291 | 291 |
// a custom error handler. |
| 292 |
- Usage func() |
|
| 292 |
+ Usage func() |
|
| 293 |
+ ShortUsage func() |
|
| 293 | 294 |
|
| 294 | 295 |
name string |
| 295 | 296 |
parsed bool |
| ... | ... |
@@ -564,6 +565,12 @@ var Usage = func() {
|
| 564 | 564 |
PrintDefaults() |
| 565 | 565 |
} |
| 566 | 566 |
|
| 567 |
+// Usage prints to standard error a usage message documenting the standard command layout |
|
| 568 |
+// The function is a variable that may be changed to point to a custom function. |
|
| 569 |
+var ShortUsage = func() {
|
|
| 570 |
+ fmt.Fprintf(CommandLine.output, "Usage of %s:\n", os.Args[0]) |
|
| 571 |
+} |
|
| 572 |
+ |
|
| 567 | 573 |
// FlagCount returns the number of flags that have been defined. |
| 568 | 574 |
func (f *FlagSet) FlagCount() int { return len(sortFlags(f.formal)) }
|
| 569 | 575 |
|
| ... | ... |
@@ -1073,6 +1080,8 @@ func (cmd *FlagSet) ParseFlags(args []string, withHelp bool) error {
|
| 1073 | 1073 |
} |
| 1074 | 1074 |
if str := cmd.CheckArgs(); str != "" {
|
| 1075 | 1075 |
cmd.ReportError(str, withHelp) |
| 1076 |
+ cmd.ShortUsage() |
|
| 1077 |
+ os.Exit(1) |
|
| 1076 | 1078 |
} |
| 1077 | 1079 |
return nil |
| 1078 | 1080 |
} |
| ... | ... |
@@ -1085,8 +1094,7 @@ func (cmd *FlagSet) ReportError(str string, withHelp bool) {
|
| 1085 | 1085 |
str += ". See '" + os.Args[0] + " " + cmd.Name() + " --help'" |
| 1086 | 1086 |
} |
| 1087 | 1087 |
} |
| 1088 |
- fmt.Fprintf(cmd.Out(), "docker: %s\n", str) |
|
| 1089 |
- os.Exit(1) |
|
| 1088 |
+ fmt.Fprintf(cmd.Out(), "docker: %s.\n", str) |
|
| 1090 | 1089 |
} |
| 1091 | 1090 |
|
| 1092 | 1091 |
// Parsed reports whether f.Parse has been called. |