-
Notifications
You must be signed in to change notification settings - Fork 1
/
introspector.go
48 lines (42 loc) · 891 Bytes
/
introspector.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
package main
import (
"gogi"
"fmt"
"os"
"strings"
)
func Display(info *gogi.GiInfo) {
name := info.GetName()
fmt.Println(name)
fmt.Println(strings.Repeat("=", len(name)))
fmt.Printf("type: %s\n", gogi.InfoTypeToString(info.Type))
}
func main() {
if len(os.Args) < 2 {
fmt.Println("usage: go run introspector.go <namespace> [symbol...]")
return
}
namespace := os.Args[1]
gogi.Init()
loaded := gogi.LoadNamespace(namespace)
if !loaded {
fmt.Printf("Failed to load namespace '%s'\n", namespace)
return
}
if len(os.Args) == 2 {
infos := gogi.GetInfos(namespace)
for _, info := range infos {
fmt.Println(info.GetName())
}
} else {
for i := 2; i < len(os.Args); i++ {
symbol := os.Args[i]
info := gogi.GetInfoByName(namespace, symbol)
if info != nil {
Display(info)
} else {
fmt.Printf("Symbol '%s' not found\n", symbol)
}
}
}
}