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
|
package options
import (
"flag"
"os"
)
func Parse(usage func(), set func(*flag.FlagSet)) *flag.FlagSet {
args := os.Args
if len(args) < 2 {
args = append(args, "")
}
fs := flag.NewFlagSet(args[1], flag.ExitOnError)
fs.Usage = func() {
usage()
}
set(fs)
fs.Parse(args[2:])
return fs
}
func AddString(fs *flag.FlagSet, opt *string, short, long, value string) {
fs.StringVar(opt, short, value, "")
fs.StringVar(opt, long, value, "")
}
func AddUint64(fs *flag.FlagSet, opt *uint64, short, long string, value uint64) {
fs.Uint64Var(opt, short, value, "")
fs.Uint64Var(opt, long, value, "")
}
|