Merge pull request #152 from eparis/no-newline-after-flags

No newline after Flags in usage
This commit is contained in:
Eric Paris 2015-09-11 18:00:50 -05:00
commit d96b4f7741
2 changed files with 15 additions and 6 deletions

View file

@ -23,10 +23,12 @@ import (
"strconv"
"strings"
"text/template"
"unicode"
)
var templateFuncs template.FuncMap = template.FuncMap{
"trim": strings.TrimSpace,
"trimRightSpace": trimRightSpace,
"rpad": rpad,
"gt": Gt,
"eq": Eq,
@ -113,6 +115,10 @@ func Eq(a interface{}, b interface{}) bool {
return false
}
func trimRightSpace(s string) string {
return strings.TrimRightFunc(s, unicode.IsSpace)
}
//rpad adds padding to the right of a string
func rpad(s string, padding int) string {
template := fmt.Sprintf("%%-%ds", padding)

View file

@ -186,6 +186,9 @@ func (c *Command) UsageFunc() (f func(*Command) error) {
} else {
return func(c *Command) error {
err := tmpl(c.Out(), c.UsageTemplate(), c)
if err != nil {
fmt.Print(err)
}
return err
}
}
@ -263,10 +266,10 @@ Available Commands:{{range .Commands}}{{if .IsAvailableCommand}}
{{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{ if .HasLocalFlags}}
Flags:
{{.LocalFlags.FlagUsages}}{{end}}{{ if .HasInheritedFlags}}
{{.LocalFlags.FlagUsages | trimRightSpace}}{{end}}{{ if .HasInheritedFlags}}
Global Flags:
{{.InheritedFlags.FlagUsages}}{{end}}{{if .HasHelpSubCommands}}
{{.InheritedFlags.FlagUsages | trimRightSpace}}{{end}}{{if .HasHelpSubCommands}}
Additional help topics:{{range .Commands}}{{if .IsHelpCommand}}
{{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{ if .HasSubCommands }}