| 1 |
{{/* gotype: github.com/wenerme/astgo/pkg/tools/xmlgen.AGICommand*/}} |
| 2 |
{{- define "agi/command"}} |
| 3 |
// {{.StructName}}Command {{.Synopsis}} |
| 4 |
{{- with .Description}} |
| 5 |
// {{end}} |
| 6 |
{{- with .Description}}{{template "comment" .}} {{end}} |
| 7 |
type {{.StructName}}Command struct { |
| 8 |
{{- range $_,$v:=.Syntax.Params}} |
| 9 |
{{- with $v.Description}} {{template "comment" (printf "%v %v" $v.Name .)}} {{end}} |
| 10 |
{{$v.Name}} {{with not $v.Required}}*{{end}}{{$v.Type}} {{with $v.Default}} // default to {{$v.Default}} {{end}} |
| 11 |
{{- end}} |
| 12 |
{{with .Syntax.Missing}} // has missing params {{- end}} |
| 13 |
} |
| 14 |
func(cmd {{.StructName}}Command)Command() (string, error) { |
| 15 |
s := []interface{}{cmd.CommandString(),{{- range $_,$v:=.Syntax.Params}} cmd.{{.Name}}, {{- end}}} |
| 16 |
return joinCommand(s), nil |
| 17 |
} |
| 18 |
func(cmd {{.StructName}}Command)CommandString()string { |
| 19 |
return "{{.Name | upper}}" |
| 20 |
} |
| 21 |
|
| 22 |
{{$s:=.}} |
| 23 |
{{- range $_,$v:=.Syntax.Params}} |
| 24 |
{{- if not $v.Required}} |
| 25 |
func (cmd {{$s.StructName}}Command)Set{{$v.Name}}(v {{$v.Type}}) {{$s.StructName}}Command { |
| 26 |
cmd.{{$v.Name}} = &v |
| 27 |
return cmd |
| 28 |
} |
| 29 |
{{- end}} |
| 30 |
{{- end}} |
| 31 |
|
| 32 |
func (c *Client) {{$s.StructName}}( |
| 33 |
{{- range $_,$v:=.Syntax.Params -}} |
| 34 |
{{- if $v.Required}} {{$v.Name | untitle}} {{$v.Type}}, {{- end -}} |
| 35 |
{{- end -}} |
| 36 |
) Response { |
| 37 |
return c.Handler.Command({{$s.StructName}}Command{ |
| 38 |
{{- range $_,$v:=.Syntax.Params}} |
| 39 |
{{- if $v.Required}} |
| 40 |
{{$v.Name}}: {{$v.Name | untitle}}, |
| 41 |
{{- end}} |
| 42 |
{{- end}} |
| 43 |
}) |
| 44 |
} |
| 45 |
|
| 46 |
{{- end}} |
| 47 |
|
| 48 |
{{/* gotype: github.com/wenerme/astgo/pkg/tools/xmlgen.SyntaxParamDoc*/}} |
| 49 |
{{- define "agi/command/field"}} |
| 50 |
{{- with .Description}} {{template "comment" (printf "%v %v" $.Name .)}} {{end}} |
| 51 |
{{$.Name}} {{with not $.Required}}*{{end}}{{$.Type}} {{with $.Default}} // default to {{$.Default}} {{end}} |
| 52 |
{{- end}} |