Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultTemplate = template.Must(template.New("default").Parse(`
package {{ .Package }}
{{ range $name, $path := .Imports -}}
import {{ $name }} "{{ $path }}"
{{ end }}
func specs() []cli.Spec {
return []cli.Spec{
{{ range .Funcs -}}
&{{ .FuncNamePriv }}Spec{
{{ if .HasDefaultOpts -}}
opt: {{ .DefaultOptsName }},
{{- end }}
},
{{ end }}
}
}
{{ range .Funcs }}
type {{ .FuncNamePriv }}Spec struct {
cmd *cli.Cmd
{{ if .HasOpts -}}
opt {{ .OptsType }}
{{- end }}
args struct {
{{ range .Args -}}
arg{{ .Idx }} {{ .Type }}
{{ end }}
}
}
func (cmd *{{ .FuncNamePriv }}Spec) Run() {
{{ .FuncName }}(
{{- if .HasOpts }}
cmd.opt,
{{ end -}}
{{- range .Args -}}
{{ if .Variadic -}}
cmd.args.arg{{ .Idx }}...,
{{- else -}}
cmd.args.arg{{ .Idx }},
{{- end }}
{{ end -}}
)
}
func (cmd *{{ .FuncNamePriv }}Spec) Cmd() *cli.Cmd {
if cmd.cmd != nil {
return cmd.cmd
}
cmd.cmd = &cli.Cmd{
RawName: {{ .FuncName | printf "%q" }},
RawDoc: {{ .Doc | printf "%q" }},
Args: []*cli.Arg{
{{ range .Args -}}
{
Name: "{{ .Name }}",
Type: "{{ .Type }}",
Variadic: {{ .Variadic }},
Value: &cmd.args.arg{{ .Idx }},
},
{{- end }}
},
Opts: []*cli.Opt{
{{ range .Opts -}}
{
Key: {{ .Key | printf "%#v" }},
RawDoc: {{ .Doc | printf "%q" }},
Value: &cmd.opt.{{ .KeyJoined }},
DefaultValue: cmd.opt.{{ .KeyJoined }},
Type: {{ .Type | printf "%q" }},
Short: {{ .Short | printf "%q" }},
},
{{- end }}
},
}
cli.Enrich(cmd.cmd)
return cmd.cmd
}
{{ end }}
`))
Functions ¶
func TemplateVars ¶
Types ¶
type Leaf ¶
type Leaf struct { // The path to the leaf field, e.g. "Root.Sub.SubOne" Key []string // The comment attached to the leaf, e.g. "Comment for SubOne field." Doc string Type types.Type Tag string }
Leaf holds information about a leaf in a tree of struct fields. For example:
type Root struct { RootOne string Sub struct { // Comment for SubOne field. SubOne string } }
Root.RootOne and Root.Sub.SubOne are leaves.
Click to show internal directories.
Click to hide internal directories.