-
Notifications
You must be signed in to change notification settings - Fork 0
/
rocketpool-cli.go
163 lines (146 loc) · 5.54 KB
/
rocketpool-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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package main
import (
"fmt"
"os"
"github.com/mitchellh/go-homedir"
"github.com/urfave/cli"
"github.com/Seb369888/smartnode/rocketpool-cli/auction"
"github.com/Seb369888/smartnode/rocketpool-cli/faucet"
"github.com/Seb369888/smartnode/rocketpool-cli/minipool"
"github.com/Seb369888/smartnode/rocketpool-cli/network"
"github.com/Seb369888/smartnode/rocketpool-cli/node"
"github.com/Seb369888/smartnode/rocketpool-cli/odao"
"github.com/Seb369888/smartnode/rocketpool-cli/queue"
"github.com/Seb369888/smartnode/rocketpool-cli/service"
"github.com/Seb369888/smartnode/rocketpool-cli/wallet"
"github.com/Seb369888/smartnode/shared"
"github.com/Seb369888/smartnode/shared/services/rocketpool"
cliutils "github.com/Seb369888/smartnode/shared/utils/cli"
"github.com/Seb369888/smartnode/shared/utils/rp"
)
// Run
func main() {
// Add logo to application help template
cli.AppHelpTemplate = fmt.Sprintf(" ________ ________ ________ ___ ________ _______ ________ \n|\\ __ \\|\\ __ \\|\\ __ \\|\\ \\ |\\ ____\\|\\ ___ \\ |\\ __ \\ \n\\ \\ \\|\\ \\ \\ \\|\\ \\ \\ \\|\\ \\ \\ \\ \\ \\ \\___|\\ \\ __/|\\ \\ \\|\\ \\ \n \\ \\ ____\\ \\ \\\\\\ \\ \\ \\\\\\ \\ \\ \\ \\ \\_____ \\ \\ \\_|/_\\ \\ __ \\ \n \\ \\ \\___|\\ \\ \\\\\\ \\ \\ \\\\\\ \\ \\ \\____\\|____|\\ \\ \\ \\_|\\ \\ \\ \\ \\ \\ \n \\ \\__\\ \\ \\_______\\ \\_______\\ \\_______\\____\\_\\ \\ \\_______\\ \\__\\ \\__\\\n \\|__| \\|_______|\\|_______|\\|_______|\\_________\\|_______|\\|__|\\|__|\n \\|_________| \n ", cli.AppHelpTemplate)
// Initialise application
app := cli.NewApp()
// Set application info
app.Name = "poolseapool"
app.Usage = "poolsea Pool CLI"
app.Version = shared.RocketPoolVersion
app.Authors = []cli.Author{
{
Name: "David Rugendyke",
Email: "david@rocketpool.net",
},
{
Name: "Jake Pospischil",
Email: "jake@rocketpool.net",
},
{
Name: "Joe Clapis",
Email: "joe@rocketpool.net",
},
{
Name: "Kane Wallmann",
Email: "kane@rocketpool.net",
},
}
app.Copyright = "(c) 2023 poolsea Pool Pty Ltd"
// Set application flags
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "allow-root, r",
Usage: "Allow poolseapool to be run as the root user",
},
cli.StringFlag{
Name: "config-path, c",
Usage: "poolsea Pool config asset `path`",
Value: "~/.rocketpool",
},
cli.StringFlag{
Name: "daemon-path, d",
Usage: "Interact with a poolsea Pool service daemon at a `path` on the host OS, running outside of docker",
},
cli.Float64Flag{
Name: "maxFee, f",
Usage: "The max fee (including the priority fee) you want a transaction to cost, in gwei",
},
cli.Float64Flag{
Name: "maxPrioFee, i",
Usage: "The max priority fee you want a transaction to use, in gwei",
},
cli.Uint64Flag{
Name: "gasLimit, l",
Usage: "[DEPRECATED] Desired gas limit",
},
cli.StringFlag{
Name: "nonce",
Usage: "Use this flag to explicitly specify the nonce that this transaction should use, so it can override an existing 'stuck' transaction",
},
cli.BoolFlag{
Name: "debug",
Usage: "Enable debug printing of API commands",
},
cli.BoolFlag{
Name: "secure-session, s",
Usage: "Some commands may print sensitive information to your terminal. " +
"Use this flag when nobody can see your screen to allow sensitive data to be printed without prompting",
},
}
// Register commands
auction.RegisterCommands(app, "auction", []string{"a"})
// Get the config path from the arguments (or use the default)
configPath := "~/.rocketpool"
for index, arg := range os.Args {
if arg == "-c" || arg == "--config-path" {
if len(os.Args)-1 == index {
fmt.Fprintf(os.Stderr, "Expected config path after %s but none was given.\n", arg)
os.Exit(1)
}
configPath = os.Args[index+1]
}
}
// Get and parse the config file
configFile := fmt.Sprintf("%s/%s", configPath, rocketpool.SettingsFile)
expandedPath, err := homedir.Expand(configFile)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to get the global config file path: %s\n", err.Error())
os.Exit(1)
}
// Stop if the config file doesn't exist yet
_, err = os.Stat(expandedPath)
if !os.IsNotExist(err) {
cfg, err := rp.LoadConfigFromFile(expandedPath)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to load the global config file: %s\n", err.Error())
os.Exit(1)
}
// Add the faucet if we're on a testnet and it has a contract address
if cfg.Smartnode.GetRplFaucetAddress() != "" {
faucet.RegisterCommands(app, "faucet", []string{"f"})
}
}
minipool.RegisterCommands(app, "minipool", []string{"m"})
network.RegisterCommands(app, "network", []string{"e"})
node.RegisterCommands(app, "node", []string{"n"})
odao.RegisterCommands(app, "odao", []string{"o"})
queue.RegisterCommands(app, "queue", []string{"q"})
service.RegisterCommands(app, "service", []string{"s"})
wallet.RegisterCommands(app, "wallet", []string{"w"})
app.Before = func(c *cli.Context) error {
// Check user ID
if os.Getuid() == 0 && !c.GlobalBool("allow-root") {
fmt.Fprintln(os.Stderr, "poolseapool should not be run as root. Please try again without 'sudo'.")
fmt.Fprintln(os.Stderr, "If you want to run poolseapool as root anyway, use the '--allow-root' option to override this warning.")
os.Exit(1)
}
return nil
}
// Run application
fmt.Println("")
if err := app.Run(os.Args); err != nil {
cliutils.PrettyPrintError(err)
}
fmt.Println("")
}