diff options
| author | Alex Flint <[email protected]> | 2015-10-31 23:57:26 -0700 |
|---|---|---|
| committer | Alex Flint <[email protected]> | 2015-10-31 23:57:26 -0700 |
| commit | f427e9f317714fc985c39ca24990852e73be5ef0 (patch) | |
| tree | d68118c2b8711df9aa8e7323d009a505e4971b8a /usage.go | |
| parent | 026a8246669cd8799d694060f46d5273a8cb6e84 (diff) | |
added parser struct
Diffstat (limited to 'usage.go')
| -rw-r--r-- | usage.go | 25 |
1 files changed, 13 insertions, 12 deletions
@@ -4,11 +4,12 @@ import ( "fmt" "io" "os" + "path/filepath" "reflect" "strings" ) -// Usage prints usage information to stdout information and exits with status zero +// Usage prints usage information to stdout and exits with status zero func Usage(dest ...interface{}) { if err := WriteUsage(os.Stdout, dest...); err != nil { fmt.Println(err) @@ -31,20 +32,12 @@ func WriteUsage(w io.Writer, dest ...interface{}) error { if err != nil { return err } - writeUsage(w, spec) + writeUsage(w, filepath.Base(os.Args[0]), spec) return nil } -func synopsis(spec *spec, form string) string { - if spec.dest.Kind() == reflect.Bool { - return form - } else { - return form + " " + strings.ToUpper(spec.long) - } -} - // writeUsage writes usage information to the given writer -func writeUsage(w io.Writer, specs []*spec) { +func writeUsage(w io.Writer, cmd string, specs []*spec) { var positionals, options []*spec for _, spec := range specs { if spec.positional { @@ -54,7 +47,7 @@ func writeUsage(w io.Writer, specs []*spec) { } } - fmt.Fprint(w, "usage: ") + fmt.Fprint(w, "usage: %s ", cmd) // write the option component of the one-line usage message for _, spec := range options { @@ -110,3 +103,11 @@ func writeUsage(w io.Writer, specs []*spec) { } } } + +func synopsis(spec *spec, form string) string { + if spec.dest.Kind() == reflect.Bool { + return form + } else { + return form + " " + strings.ToUpper(spec.long) + } +} |
