Browse Source

Remove excess trailing whitespace from Usage generation

Brett Langdon 10 years ago
parent
commit
383b8b84c1
2 changed files with 7 additions and 5 deletions
  1. +5
    -3
      usage.go
  2. +2
    -2
      usage_test.go

+ 5
- 3
usage.go View File

@ -27,10 +27,12 @@ func (p *Parser) WriteUsage(w io.Writer) {
}
}
fmt.Fprintf(w, "usage: %s ", filepath.Base(os.Args[0]))
fmt.Fprintf(w, "usage: %s", filepath.Base(os.Args[0]))
// write the option component of the usage message
for _, spec := range options {
// prefix with a space
fmt.Fprint(w, " ")
if !spec.required {
fmt.Fprint(w, "[")
}
@ -38,18 +40,18 @@ func (p *Parser) WriteUsage(w io.Writer) {
if !spec.required {
fmt.Fprint(w, "]")
}
fmt.Fprint(w, " ")
}
// write the positional component of the usage message
for _, spec := range positionals {
// prefix with a space
fmt.Fprint(w, " ")
up := strings.ToUpper(spec.long)
if spec.multiple {
fmt.Fprintf(w, "[%s [%s ...]]", up, up)
} else {
fmt.Fprint(w, up)
}
fmt.Fprint(w, " ")
}
fmt.Fprint(w, "\n")
}


+ 2
- 2
usage_test.go View File

@ -10,9 +10,9 @@ import (
)
func TestWriteUsage(t *testing.T) {
expectedUsage := "usage: example [--verbose] [--dataset DATASET] [--optimize OPTIMIZE] INPUT [OUTPUT [OUTPUT ...]] \n"
expectedUsage := "usage: example [--verbose] [--dataset DATASET] [--optimize OPTIMIZE] INPUT [OUTPUT [OUTPUT ...]]\n"
expectedHelp := `usage: example [--verbose] [--dataset DATASET] [--optimize OPTIMIZE] INPUT [OUTPUT [OUTPUT ...]]
expectedHelp := `usage: example [--verbose] [--dataset DATASET] [--optimize OPTIMIZE] INPUT [OUTPUT [OUTPUT ...]]
positional arguments:
input


Loading…
Cancel
Save