Skip to content

Commit 0cc6d0b

Browse files
committed
- [+] add nested_demo_argsm_opt test/demo
1 parent 23ee694 commit 0cc6d0b

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

test/nested_demo_argsm_opt.tmpl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{{define "type_struct" -}}
2+
3+
// The {{.typeName}} type defines all the configurable options from cli.
4+
type {{.typeName}} struct { {{- range .Options}}
5+
{{- if eq .Name "Args" }}
6+
7+
{{.Args}}
8+
{{- else }}{{$f := stringsSplit .Flag ","}}{{ $flen := len $f }}
9+
{{.Name}} {{.Type}} `short:"{{index $f 0}}"{{if gt $flen 1}} long:"{{index $f 1}}"{{end}}{{if .EnvV}} env:"{{printf "%s_%s" (clk2ss $.ProgramName) (clk2ss .Name)}}"{{end}} description:"{{.Usage}}"{{if .Value}} default:"{{.Value}}"{{end}}`{{end}}
10+
{{- end}}
11+
{{- if .Verbose}}
12+
Verbflg func() `short:"v" long:"verbose" description:"Verbose mode (Multiple -v options increase the verbosity)"`
13+
Verbose uint
14+
{{end}}
15+
{{- end -}}
16+
17+
{{range .Command}}
18+
////////////////////////////////////////////////////////////////////////////
19+
// {{.Name}}
20+
21+
{{template "type_struct" argsm "Options" .Options "typeName" (print (stringsTitle .Name) "Command") }}
22+
}
23+
{{end}}

test/nested_demo_argsm_opt.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Command:
2+
3+
- Name: publish
4+
Desc: "Publish application"
5+
Text: 'Publish the network application"'
6+
7+
Options:
8+
- Name: Dir
9+
Type: string
10+
Flag: '*d,dir'
11+
Usage: publish dir
12+
13+
- Name: Suffix
14+
Type: string
15+
Flag: suffix
16+
Value: ".go,.c,.s"
17+
Usage: "source file suffix"
18+
19+
- Name: Out
20+
Type: string
21+
Flag: o,out
22+
Usage: "output filename"
23+
24+
- Name: List
25+
Type: bool
26+
Flag: l,list
27+
Usage: "list all sub commands"
28+
29+
- Name: Args
30+
Args: |
31+
// Example of positional arguments
32+
Args struct {
33+
ID string
34+
Num int
35+
Rest []string
36+
"} `positional-args:"yes" required:"yes"`"

0 commit comments

Comments
 (0)