/
cmd_root.go
72 lines (61 loc) · 1.55 KB
/
cmd_root.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
package main
import (
"context"
"fmt"
"runtime"
"runtime/debug"
"github.com/spf13/cobra"
"storj.io/crypto-batch-payment/pkg/storjtoken"
)
const (
defaultNodeAddress = "/home/storj/.ethereum/geth.ipc"
defaultDataDir = "."
)
type rootConfig struct {
Ctx context.Context
NodeAddress string
ChainID string
DataDir string
}
func newRootCommand() *cobra.Command {
config := new(rootConfig)
cmd := &cobra.Command{
Use: "payouts",
Short: "Manage and execute STORJ Token payouts",
PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) {
config.Ctx = cmdCtx()
return nil
},
Version: getVersion(),
}
cmd.PersistentFlags().StringVarP(
&config.NodeAddress,
"node-address", "",
defaultNodeAddress,
"Address of the ETH node to use")
cmd.PersistentFlags().StringVarP(
&config.ChainID,
"chain-id", "",
storjtoken.DefaultChainID.String(),
"Address of the STORJ contract on the network")
cmd.PersistentFlags().StringVarP(
&config.DataDir,
"data-dir", "",
defaultDataDir,
"Directory to store data (e.g. payout metadata)")
cmd.AddCommand(newImportCommand(config))
cmd.AddCommand(newRunCommand(config))
cmd.AddCommand(newStatCommand(config))
cmd.AddCommand(newAuditCommand(config))
cmd.AddCommand(newPriceCommand(config))
cmd.AddCommand(newZkSyncCommand(config))
cmd.AddCommand(newPayerCommand(config))
return cmd
}
func getVersion() string {
buildInfo, ok := debug.ReadBuildInfo()
if !ok {
return "unknown"
}
return fmt.Sprintf("%s (built with %s)\n", buildInfo.Main.Version, runtime.Version())
}