-
Notifications
You must be signed in to change notification settings - Fork 0
/
command_flags.go
240 lines (219 loc) · 6.48 KB
/
command_flags.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
package cmd
import "github.com/urfave/cli/v2"
// command-line flags used by multiple different tex-cli commands
// MultiAddrFlag indicates the multi address to use
func MultiAddrFlag(usage string) *cli.StringFlag {
return &cli.StringFlag{
Name: "multi.address",
Aliases: []string{"ma"},
Usage: usage,
EnvVars: []string{"TEX_MULTI_ADDRESS", "TEX_MA"},
}
}
// PeerIDFlag indicates the peerID
func PeerIDFlag(usage string) *cli.StringFlag {
return &cli.StringFlag{
Name: "peer.id",
Aliases: []string{"pid"},
Usage: usage,
EnvVars: []string{"TEX_PEER_ID", "TEX_PID"},
}
}
// CidFlag is used to indicate the cid to proccess
func CidFlag(usage string) *cli.StringFlag {
return &cli.StringFlag{
Name: "cid",
Usage: usage,
EnvVars: []string{"TEX_CID"},
}
}
// PrintProgressFlag enables printing the progress of uploads
func PrintProgressFlag() *cli.BoolFlag {
return &cli.BoolFlag{
Name: "print.progress",
Aliases: []string{"pp"},
Usage: "print progress of uploads/downloads",
EnvVars: []string{"TEX_PRINT_PROGRESS", "TEX_PP"},
}
}
// OutputFlag helps to control the style of output
func OutputFlag() *cli.StringFlag {
return &cli.StringFlag{
Name: "output",
Usage: "control output, accepts 'print' or 'monitor'",
Value: "print",
EnvVars: []string{"TEX_OUTPUT"},
}
}
// KeyName indicates the name of the key
func KeyName() *cli.StringFlag {
return &cli.StringFlag{
Name: "key.name",
Aliases: []string{"kn"},
Usage: "name of the key used in the keystore",
EnvVars: []string{"TEX_KEY_NAME", "TEX_KN"},
}
}
// KeyType indicates the type of key
func KeyType() *cli.StringFlag {
return &cli.StringFlag{
Name: "key.type",
Aliases: []string{"kt"},
Usage: "type of key: ed25519, ecdsa, rsa, secp256k1",
EnvVars: []string{"TEX_KEY_TYPE", "TEX_KT"},
}
}
// KeySize indicates the size of a key, default size suitable for all but RSA
func KeySize() *cli.IntFlag {
return &cli.IntFlag{
Name: "key.size",
Value: 256,
Aliases: []string{"ks"},
Usage: "size of key in bytes",
EnvVars: []string{"TEX_KEY_SIZE", "TEX_KS"},
}
}
// MnemonicFlag allows saving data as a mnemonic
func MnemonicFlag() *cli.StringFlag {
return &cli.StringFlag{
Name: "save.mnemonic",
Aliases: []string{"sm"},
Usage: "save mnemonic to `PATH` if not empty",
Value: "",
EnvVars: []string{"TEX_SAVE_MNEMONIC", "TEX_SM"},
}
}
// InputFileFlag allows reading data from a file
func InputFileFlag() *cli.StringFlag {
return &cli.StringFlag{
Name: "input.file",
Aliases: []string{"in.fi", "if"},
Usage: "load data contained in file at `PATH`",
EnvVars: []string{"TEX_INPUT_FILE", "TEX_IF"},
}
}
// IsHexEncodedFlag indicates if the data is hex encoded
func IsHexEncodedFlag() *cli.BoolFlag {
return &cli.BoolFlag{
Name: "hex.encoded",
Value: false,
Usage: "whether or not the key has been hex encoded",
EnvVars: []string{"HEX_ENCODED"},
}
}
// IsMnemonicEncodedFlag indicates if the data is encoded as mnemonic
func IsMnemonicEncodedFlag() *cli.BoolFlag {
return &cli.BoolFlag{
Name: "mnemonic.encoded",
Value: true,
Usage: "whether or not the key has been converted into a mnemonic",
EnvVars: []string{"TEX_MNEMONIC_ENCODED"},
}
}
// LinkNameFlag indicates the name of a link in IPLD object management
func LinkNameFlag(usage string) *cli.StringFlag {
return &cli.StringFlag{
Name: "link.name",
Aliases: []string{"ln"},
Usage: usage,
EnvVars: []string{"TEX_LINK_NAME"},
}
}
// LinkCidFlag indicates the cid of a link
func LinkCidFlag(usage string) *cli.StringFlag {
return &cli.StringFlag{
Name: "link.cid",
Aliases: []string{"lc"},
Usage: usage,
EnvVars: []string{"TEX_LINK_CID"},
}
}
// DataFlag indicates some arbitrary string data
func DataFlag(usage string) *cli.StringFlag {
return &cli.StringFlag{
Name: "data",
Aliases: []string{"d"},
Usage: usage,
EnvVars: []string{"TEX_DATA"},
}
}
// ObjectEncodingFlag enables specifying alternate encoding formats for creating objects
func ObjectEncodingFlag() *cli.StringFlag {
return &cli.StringFlag{
Name: "object.encoding",
Aliases: []string{"obj.enc", "oe"},
Usage: "the type of encoding used to create an object",
Value: "raw",
}
}
// SerializationFormatFlag enables specifying alternate serialization formats
func SerializationFormatFlag() *cli.StringFlag {
return &cli.StringFlag{
Name: "serialization.format",
Aliases: []string{"serial.form", "sfmt", "st"},
Usage: "the type of serialization to use when creating the object",
Value: "raw",
EnvVars: []string{"TEX_SERIALIZATION_FORMAT", "TEX_SERIAL_FORM"},
}
}
// MultiHashFlag enables specifying the multihash to use
func MultiHashFlag() *cli.StringFlag {
return &cli.StringFlag{
Name: "multihash",
Aliases: []string{"mhash", "mh"},
Usage: "specify the multihash to use in object creation",
Value: "sha2-256",
EnvVars: []string{"TEX_MULTI_HASH"},
}
}
// P2pFlags are used to control p2p stream
// takes in an argument which is a command that should be
// loaded with a default value. This is appended to the default
// p2p command flag list
func P2pFlags(cmdFlag *cli.StringFlag) []cli.Flag {
if cmdFlag.Value == "" {
panic("flag value is nil")
}
return append([]cli.Flag{
&cli.BoolFlag{
Name: "all",
Usage: "close all listeners. used by: close",
EnvVars: []string{"TEX_ALL"},
},
&cli.BoolFlag{
Name: "verbose",
Usage: "print protocol, listen and target information. used by ls",
EnvVars: []string{"TEX_VERBOSE"},
},
&cli.BoolFlag{
Name: "custom.protocols",
Usage: "disables requiring /x/ prefix. used by: listen, forward",
EnvVars: []string{"TEX_CUSTOM_PROTOCOLS"},
},
&cli.BoolFlag{
Name: "report.peerid",
Usage: "send base58 peerID to target. used by: listen",
EnvVars: []string{"TEX_REPORT_PEERID"},
},
&cli.StringFlag{
Name: "protocol.name",
Usage: "match/set protocol name. used by: close, forward, listen",
EnvVars: []string{"TEX_PROTOCOL_NAME"},
},
&cli.StringFlag{
Name: "listen.address",
Usage: "match/set against listen address. used by: close, forward",
EnvVars: []string{"TEX_LISTEN_ADDRESS"},
},
&cli.StringFlag{
Name: "target.address",
Usage: "match/set against target address. used by: close, forward, listen",
EnvVars: []string{"TEX_TARGET_ADDRESS"},
},
&cli.StringFlag{
Name: "remote.address",
Usage: "note currently used but here for compatability",
EnvVars: []string{"TEX_REMOTE_ADDRESS"},
},
}, cmdFlag)
}