-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
64 lines (55 loc) · 1.08 KB
/
example_test.go
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package fcli_test
import (
"flag"
"fmt"
"github.com/berquerant/fcli"
)
func ExampleNewFlagFactory_basicTypes() {
var (
boolFlagF, _ = fcli.NewFlagFactory(false)
stringFlagF, _ = fcli.NewFlagFactory("")
boolFlag = boolFlagF("b")
stringFlag = stringFlagF("s")
flagSet = flag.NewFlagSet("ff", flag.ContinueOnError)
)
boolFlag.AddFlag(flagSet)
stringFlag.AddFlag(flagSet)
if err := flagSet.Parse([]string{"-b", "-s", "basic"}); err != nil {
panic(err)
}
b, _ := boolFlag.Unwrap()
s, _ := stringFlag.Unwrap()
fmt.Println(b)
fmt.Println(s)
// Output:
// true
// basic
}
func ExampleGetFuncName() {
v, err := fcli.GetFuncName(fmt.Println)
if err != nil {
panic(err)
}
fmt.Println(v)
// Output:
// Println
}
func ExampleNewFuncInfo() {
const src = `// Hello greets you.
func Hello(name string) {
println("Hello!", name)
}`
info, err := fcli.NewFuncInfo(src)
if err != nil {
panic(err)
}
fmt.Println(info.Name())
fmt.Println(info.NumIn())
fmt.Println(info.In(0).Name())
fmt.Println(info.Doc())
// Output:
// Hello
// 1
// name
// Hello greets you.
}