Add markdown and man page docs generation methods

This adds two new methods to the `App` struct:

- `ToMarkdown`: creates a markdown documentation string
- `ToMan`: creates a man page string

Signed-off-by: Sascha Grunert <mail@saschagrunert.de>
This commit is contained in:
Sascha Grunert
2019-08-03 12:41:50 +02:00
committed by Sascha Grunert
parent 97179ca390
commit 40d4a25a01
17 changed files with 908 additions and 103 deletions

View File

@@ -4,6 +4,7 @@ package {{ .PackageName }}
import (
"flag"
"fmt"
"strconv"
"time"
)
@@ -40,6 +41,22 @@ func (f {{ $flag.Name }}Flag) IsRequired() bool {
return f.Required
}
// TakesValue returns true of the flag takes a value, otherwise false
func (f {{ $flag.Name }}Flag) TakesValue() bool {
return {{ $flag.Value }}
}
// GetUsage returns the usage string for the flag
func (f {{ $flag.Name }}Flag) GetUsage() string {
return f.Usage
}
// GetValue returns the flags value as string representation and an empty
// string if the flag takes no value at all.
func (f {{ $flag.Name }}Flag) GetValue() string {
{{ $flag.ValueString }}
}
// {{ $flag.Name }} looks up the value of a local {{ $flag.Name }}Flag, returns
// {{ $flag.ContextDefault }} if not found
func (c *Context) {{ $flag.Name }}(name string) {{ if ne .ContextType "" }}{{ $flag.ContextType }}{{ else }}{{ $flag.Type }}{{- end }} {
@@ -66,4 +83,4 @@ func lookup{{ $flag.Name }}(name string, set *flag.FlagSet) {{ if ne .ContextTyp
}
return {{ $flag.ContextDefault }}
}
{{ end }}
{{ end }}