diff options
| author | Alex Flint <[email protected]> | 2016-01-18 08:58:11 -0800 |
|---|---|---|
| committer | Alex Flint <[email protected]> | 2016-01-18 08:58:11 -0800 |
| commit | c9155bb0c3e57557bae7d7c54b60ab8fe2e95211 (patch) | |
| tree | ca87fe752f37ce817559efa60f58ef27e7be6c35 /usage.go | |
| parent | f8ea16beeeb29e99546599ca08095378a124262f (diff) | |
| parent | 4197d283e41bbce1a2cac20ea56fd1156a677db1 (diff) | |
Merge pull request #26 from alexflint/brettlangdon-dev/positional.help.sqwished
Resolve some merge conflicts from #8
Diffstat (limited to 'usage.go')
| -rw-r--r-- | usage.go | 16 |
1 files changed, 14 insertions, 2 deletions
@@ -9,6 +9,9 @@ import ( "strings" ) +// the width of the left column +const colWidth = 25 + // Fail prints usage information to stderr and exits with non-zero status func (p *Parser) Fail(msg string) { p.WriteUsage(os.Stderr) @@ -73,7 +76,17 @@ func (p *Parser) WriteHelp(w io.Writer) { if len(positionals) > 0 { fmt.Fprint(w, "\npositional arguments:\n") for _, spec := range positionals { - fmt.Fprintf(w, " %s\n", spec.long) + left := " " + spec.long + fmt.Fprint(w, left) + if spec.help != "" { + if len(left)+2 < colWidth { + fmt.Fprint(w, strings.Repeat(" ", colWidth-len(left))) + } else { + fmt.Fprint(w, "\n"+strings.Repeat(" ", colWidth)) + } + fmt.Fprint(w, spec.help) + } + fmt.Fprint(w, "\n") } } @@ -88,7 +101,6 @@ func (p *Parser) WriteHelp(w io.Writer) { } func printOption(w io.Writer, spec *spec) { - const colWidth = 25 left := " " + synopsis(spec, "--"+spec.long) if spec.short != "" { left += ", " + synopsis(spec, "-"+spec.short) |
