Skip to content

Commit

Permalink
Change -help flags summary to printout the alias instead of the full …
Browse files Browse the repository at this point in the history
…name
  • Loading branch information
Makis Maropoulos committed May 28, 2016
1 parent 54f6863 commit 7047ead
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ func (a App) help() {
}

func (a App) HasCommands() bool {
if a.Commands != nil && len(a.Commands) > 0 {
return true
}
return a.Commands != nil && len(a.Commands) > 0
}

return false
func (a App) HasFlags() bool {
return a.Flags != nil && len(a.Flags) > 0
}

func (a App) Run(appAction Action) {
Expand All @@ -109,7 +109,7 @@ func (a App) Run(appAction Action) {
}
}

if len(os.Args) < 1 {
if len(os.Args) <= 1 {
a.help()
}

Expand Down Expand Up @@ -160,17 +160,21 @@ var appTmpl = `NAME:
{{.Name}} - {{.Description}}
USAGE:
{{- if .HasFlags}}
{{.Name}} [global arguments...]
{{end -}}
{{ if .HasCommands }}
{{.Name}} command [arguments...]
{{ end }}
VERSION:
{{.Version}}
{{- if.HasFlags}}
GLOBAL ARGUMENTS:
{{ range $idx,$flag := .Flags }}
-{{$flag.Alias }} {{$flag.Usage}} (default '{{$flag.Default}}')
{{ end }}
{{end -}}
{{ if .HasCommands }}
COMMANDS:
{{ range $index, $cmd := .Commands }}
Expand Down
2 changes: 1 addition & 1 deletion flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (c Flags) Validate() error {

func (c Flags) ToString() (summary string) {
for idx, v := range c {
summary += "-" + v.Name
summary += "-" + v.Alias()
if idx < len(c)-1 {
summary += ", "
}
Expand Down

0 comments on commit 7047ead

Please sign in to comment.