-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (54 loc) · 1.06 KB
/
main.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
package main
import (
"flag"
"fmt"
"github.com/hackborn/ghost/graph"
"os"
"os/signal"
"syscall"
)
func main() {
g, err := loadGraph()
if err != nil {
fmt.Println("Error loading graph:", err)
return
}
if g == nil {
fmt.Println("Unknown error loading graph:")
return
}
done := make(chan bool)
c := make(chan os.Signal, 2)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
done <- true
}()
g.Start()
<-done
g.Stop()
}
func loadGraph() (*graph.Graph, error) {
// 1. Load graph based on the command line
// Provide defaults for now
graph_name := "test"
if len(os.Args) > 1 {
graph_name = os.Args[1]
}
return graph.Load(graph_name, loadCla)
}
// Load graph arguments from the command line.
func loadCla(args *graph.Args) {
if len(os.Args) <= 2 {
return
}
fs := flag.NewFlagSet("fs", flag.ContinueOnError)
var values []*string
for _, a := range args.Arg {
values = append(values, fs.String(a.XMLName.Local, a.Value, a.Usage))
}
fs.Parse(os.Args[2:])
for i := 0; i < len(values); i++ {
args.Arg[i].Value = *(values[i])
}
}