Skip to content

Commit f4677fb

Browse files
committed
- [+] add duration flag support to commandlineFlag
1 parent dcf8840 commit f4677fb

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

test/commandlineFlag.ref

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type Options struct {
2424
ExtTmpl string // `extension` of template file
2525
StrFrom string // replace from, the from string used for the replace function
2626
StrTo string // replace to, the to string used for the replace function
27+
Batch time.Duration // batch interval
2728
Debug int // debugging `level`
2829
}
2930

@@ -55,6 +56,8 @@ func initVars() {
5556
"replace from, the from string used for the replace function")
5657
flag.StringVar(&Opts.StrTo, "rt", "",
5758
"replace to, the to string used for the replace function")
59+
flag.DurationVar(&Opts.Batch, "batch", 120*time.Second,
60+
"batch interval")
5861
flag.IntVar(&Opts.Debug, "d", 0,
5962
"debugging `level`")
6063
flag.IntVar(&Opts.Debug, "debug", 0,

test/commandlineFlag.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const progname = "{{.ProgramName}}" // os.Args[0]
1717

1818
// The {{.StructName}} struct defines the structure to hold the commandline values
1919
type {{.StructName}} struct { {{range .Options}}{{if ne .Name "SEPARATOR" }}
20-
{{.Name}} {{.Type}} // {{.Usage}}{{end}}{{end}}
20+
{{.Name}} {{ if eq .Type "duration" }}time.Duration{{else}}{{.Type}}{{end}} // {{.Usage}}{{end}}{{end}}
2121
}
2222

2323
////////////////////////////////////////////////////////////////////////////

test/commandlineFlag.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ Options:
6262
Value: '""'
6363
Usage: "replace to, the to string used for the replace function"
6464

65+
- Name: Batch
66+
Type: duration
67+
Flag: batch
68+
Value: '120*time.Second'
69+
Usage: "batch interval"
70+
6571
- Name: Debug
6672
Type: int
6773
Flag: d,debug

0 commit comments

Comments
 (0)