This repository has been archived by the owner on Feb 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
cli.go
142 lines (120 loc) · 2.66 KB
/
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package main
import (
"os"
"time"
"github.com/champii/crypto-dht/blockchain"
"github.com/urfave/cli"
)
func parseArgs(done func(blockchain.BlockchainOptions)) {
app := setupCli()
app.Action = func(c *cli.Context) error {
options := blockchain.BlockchainOptions{
ListenAddr: c.String("l"),
BootstrapAddr: c.String("c"),
Folder: c.String("f"),
Send: c.String("S"),
Verbose: c.Int("v"),
Stats: c.Bool("s"),
Wallets: c.Bool("w"),
NoGui: c.Bool("g"),
Mine: c.Bool("m"),
Cluster: c.Int("n"),
}
if options.Cluster > 0 {
options.Send = ""
options.Stats = false
options.NoGui = true
options.Wallets = false
}
if options.Stats || len(options.Send) > 0 {
options.NoGui = true
options.Wallets = false
}
if len(options.Send) > 0 {
options.Stats = false
}
done(options)
return nil
}
app.Run(os.Args)
}
func setupCli() *cli.App {
cli.AppHelpTemplate = `NAME:
{{.Name}} - {{.Usage}}
USAGE:
{{if .VisibleFlags}}{{.HelpName}} [options]{{end}}
{{if len .Authors}}
AUTHOR:
{{range .Authors}}{{ . }}{{end}}
{{end}}{{if .Commands}}
VERSION:
{{.Version}}
OPTIONS:
{{range .VisibleFlags}}{{.}}
{{end}}{{end}}{{if .Copyright }}
COPYRIGHT:
{{.Copyright}}
{{end}}{{if .Version}}
{{end}}`
cli.VersionFlag = cli.BoolFlag{
Name: "V, version",
Usage: "Print version",
}
cli.HelpFlag = cli.BoolFlag{
Name: "h, help",
Usage: "Print help",
}
app := cli.NewApp()
app.Name = "Crypto-Dht"
app.Version = "0.1.0"
app.Compiled = time.Now()
app.Usage = "Experimental Blockchain over DHT"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "c, connect",
Usage: "Connect to node ip:port. If not set, startup a bootstrap node.",
},
cli.StringFlag{
Name: "l, listen",
Usage: "Listening address and port",
Value: "0.0.0.0:3000",
},
cli.StringFlag{
Name: "f, folder",
Usage: "Config Folder",
Value: os.Getenv("HOME") + "/.crypto-dht",
},
cli.BoolFlag{
Name: "s",
Usage: "Stat mode",
},
cli.BoolFlag{
Name: "m",
Usage: "Mine",
},
cli.BoolFlag{
Name: "w",
Usage: "Show wallets and amount",
},
cli.BoolFlag{
Name: "g",
Usage: "Deactivate GUI",
},
cli.StringFlag{
Name: "S, send",
Usage: "Send coins from main.key. Must be of the form 'amount:destAddress'",
},
cli.IntFlag{
Name: "n, network",
Value: 0,
Usage: "Spawn X new `nodes` network. If -b is not specified, a new network is created.",
},
cli.IntFlag{
Name: "v, verbose",
Value: 3,
Usage: "Verbose `level`, 0 for CRITICAL and 5 for DEBUG",
},
}
app.UsageText = "./crypto-dht [options]"
return app
}