-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.go
55 lines (44 loc) · 988 Bytes
/
cli.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
package main
import (
"os"
)
// HandleCmdIfCLI if one or more commands specified, run agora in CLI
// mode (means that agora terminates immidiately after execution
func HandleCmdIfCLI() {
isCLI := false
// Add Known peers
if len(opts.AddPeers) != 0 {
isCLI = true
for _, p := range opts.AddPeers {
Info.Println("Add peer with id", p)
err := MyNode.AddPeer(p)
if err != nil {
panic(err)
}
}
}
// Delete all known peers
if opts.DeletePeers {
isCLI = true
Info.Println("Remove all known peers")
err := MyNode.RemoveAllPeers()
if err != nil {
panic(err)
}
}
if opts.Initt {
isCLI = true
Info.Println("Node initialized as", MyNode.ID)
}
// Pull all posts from a given node
if opts.PullPosts != "" {
isCLI = true
Info.Println("Pull all posts form peer", opts.PullPosts)
MyNode.pullPostFrom(opts.PullPosts)
Info.Println("Done pulling")
}
// Just terminate the program as we use it in CLI mode
if isCLI {
os.Exit(0)
}
}