-
Notifications
You must be signed in to change notification settings - Fork 16
/
templates.go
53 lines (38 loc) · 1.55 KB
/
templates.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package commando
var usageTemplate = `
{{ if .IsRootCommand }}{{ .CliDesc }}{{ else }}{{ .Desc }}{{ end }}
Usage:
{{ .Executable }} {{ if not .IsRootCommand }}{{ .Command }} {{ end }}{{ with .Args -}}
{{ range $k, $v := . }}{{ if $v.IsRequired }}<{{ $v.ClpArg.Name }}>{{ else }}[{{ $v.ClpArg.Name }}]{{ end }} {{ end }}{{ end }}{flags}{{- if .IsRootCommand }}{{ if .Commands }}
{{ .Executable }} <command> {flags}{{ end }}{{ end -}}
{{- /* commands */ -}}
{{- if .IsRootCommand -}}
{{- with .Commands }}
Commands: {{ range $k, $v := . }}
{{ printf "%-30v" $k }}{{ $v.ShortDesc }}
{{- end -}}
{{- end -}}
{{- end -}}
{{- /* arguments */ -}}
{{- with .Args }}
Arguments: {{ range $k, $v := . }}
{{ printf "%-30v" $v.ClpArg.Name }}{{ $v.Desc }}{{ if $v.ClpArg.DefaultValue }} (default: {{ $v.ClpArg.DefaultValue }}){{ end }}{{ if $v.ClpArg.IsVariadic }} {variadic}{{ end }}
{{- end -}}
{{- end -}}
{{- /* flags */ -}}
{{- with .Flags }}
Flags: {{ range $k, $v := . }}
{{ if $v.ClpFlag.ShortName -}}-{{ $v.ClpFlag.ShortName }}, {{ if $v.ClpFlag.IsInverted }}{{ printf "--no-%-24v" $k }}{{ else }}{{ printf "--%-24v" $k }}{{ end -}}
{{ else }}{{ if $v.ClpFlag.IsInverted }}{{ printf "--no-%-25v" $k }}{{ else }}{{ printf "--%-28v" $k }}{{ end -}}
{{- end -}}
{{- $v.Desc }} {{ if $v.ClpFlag.DefaultValue }}(default: {{ if $v.ClpFlag.IsInverted }}false{{ else }}{{ $v.ClpFlag.DefaultValue }}{{ end }}){{ end }}
{{- end -}}
{{- end -}}
{{- /* end */ -}}
{{- "" }}
`
var versionTemplate = `
Version: {{ .Version }}
{{- /* end */ -}}
{{- "" }}
`