Skip to content

Commit 63c5a46

Browse files
committed
[release/1.4.7] cmd: fix CLI package deprecation warnings
(cherry picked from commit 90e07b1)
1 parent c89fa78 commit 63c5a46

File tree

8 files changed

+55
-27
lines changed

8 files changed

+55
-27
lines changed

cmd/ethtest/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func runSuite(test, file string) {
183183
}
184184
}
185185

186-
func setupApp(c *cli.Context) {
186+
func setupApp(c *cli.Context) error {
187187
flagTest := c.GlobalString(TestFlag.Name)
188188
flagFile := c.GlobalString(FileFlag.Name)
189189
continueOnError = c.GlobalBool(ContinueOnErrorFlag.Name)
@@ -196,8 +196,8 @@ func setupApp(c *cli.Context) {
196196
if err := runTestWithReader(flagTest, os.Stdin); err != nil {
197197
glog.Fatalln(err)
198198
}
199-
200199
}
200+
return nil
201201
}
202202

203203
func main() {

cmd/evm/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func init() {
104104
app.Action = run
105105
}
106106

107-
func run(ctx *cli.Context) {
107+
func run(ctx *cli.Context) error {
108108
glog.SetToStderr(true)
109109
glog.SetV(ctx.GlobalInt(VerbosityFlag.Name))
110110

@@ -154,6 +154,7 @@ num gc: %d
154154
fmt.Printf(" error: %v", e)
155155
}
156156
fmt.Println()
157+
return nil
157158
}
158159

159160
func main() {

cmd/geth/accountcmd.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,12 @@ nodes.
167167
}
168168
)
169169

170-
func accountList(ctx *cli.Context) {
170+
func accountList(ctx *cli.Context) error {
171171
accman := utils.MakeAccountManager(ctx)
172172
for i, acct := range accman.Accounts() {
173173
fmt.Printf("Account #%d: {%x} %s\n", i, acct.Address, acct.File)
174174
}
175+
return nil
175176
}
176177

177178
// tries unlocking the specified account a few times.
@@ -259,7 +260,7 @@ func ambiguousAddrRecovery(am *accounts.Manager, err *accounts.AmbiguousAddrErro
259260
}
260261

261262
// accountCreate creates a new account into the keystore defined by the CLI flags.
262-
func accountCreate(ctx *cli.Context) {
263+
func accountCreate(ctx *cli.Context) error {
263264
accman := utils.MakeAccountManager(ctx)
264265
password := getPassPhrase("Your new account is locked with a password. Please give a password. Do not forget this password.", true, 0, utils.MakePasswordList(ctx))
265266

@@ -268,11 +269,12 @@ func accountCreate(ctx *cli.Context) {
268269
utils.Fatalf("Failed to create account: %v", err)
269270
}
270271
fmt.Printf("Address: {%x}\n", account.Address)
272+
return nil
271273
}
272274

273275
// accountUpdate transitions an account from a previous format to the current
274276
// one, also providing the possibility to change the pass-phrase.
275-
func accountUpdate(ctx *cli.Context) {
277+
func accountUpdate(ctx *cli.Context) error {
276278
if len(ctx.Args()) == 0 {
277279
utils.Fatalf("No accounts specified to update")
278280
}
@@ -283,9 +285,10 @@ func accountUpdate(ctx *cli.Context) {
283285
if err := accman.Update(account, oldPassword, newPassword); err != nil {
284286
utils.Fatalf("Could not update the account: %v", err)
285287
}
288+
return nil
286289
}
287290

288-
func importWallet(ctx *cli.Context) {
291+
func importWallet(ctx *cli.Context) error {
289292
keyfile := ctx.Args().First()
290293
if len(keyfile) == 0 {
291294
utils.Fatalf("keyfile must be given as argument")
@@ -303,9 +306,10 @@ func importWallet(ctx *cli.Context) {
303306
utils.Fatalf("%v", err)
304307
}
305308
fmt.Printf("Address: {%x}\n", acct.Address)
309+
return nil
306310
}
307311

308-
func accountImport(ctx *cli.Context) {
312+
func accountImport(ctx *cli.Context) error {
309313
keyfile := ctx.Args().First()
310314
if len(keyfile) == 0 {
311315
utils.Fatalf("keyfile must be given as argument")
@@ -321,4 +325,5 @@ func accountImport(ctx *cli.Context) {
321325
utils.Fatalf("Could not create the account: %v", err)
322326
}
323327
fmt.Printf("Address: {%x}\n", acct.Address)
328+
return nil
324329
}

cmd/geth/chaincmd.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Use "ethereum dump 0" to dump the genesis block.
7272
}
7373
)
7474

75-
func importChain(ctx *cli.Context) {
75+
func importChain(ctx *cli.Context) error {
7676
if len(ctx.Args()) != 1 {
7777
utils.Fatalf("This command requires an argument.")
7878
}
@@ -84,9 +84,10 @@ func importChain(ctx *cli.Context) {
8484
utils.Fatalf("Import error: %v", err)
8585
}
8686
fmt.Printf("Import done in %v", time.Since(start))
87+
return nil
8788
}
8889

89-
func exportChain(ctx *cli.Context) {
90+
func exportChain(ctx *cli.Context) error {
9091
if len(ctx.Args()) < 1 {
9192
utils.Fatalf("This command requires an argument.")
9293
}
@@ -114,9 +115,10 @@ func exportChain(ctx *cli.Context) {
114115
utils.Fatalf("Export error: %v\n", err)
115116
}
116117
fmt.Printf("Export done in %v", time.Since(start))
118+
return nil
117119
}
118120

119-
func removeDB(ctx *cli.Context) {
121+
func removeDB(ctx *cli.Context) error {
120122
confirm, err := console.Stdin.PromptConfirm("Remove local database?")
121123
if err != nil {
122124
utils.Fatalf("%v", err)
@@ -132,9 +134,10 @@ func removeDB(ctx *cli.Context) {
132134
} else {
133135
fmt.Println("Operation aborted")
134136
}
137+
return nil
135138
}
136139

137-
func upgradeDB(ctx *cli.Context) {
140+
func upgradeDB(ctx *cli.Context) error {
138141
glog.Infoln("Upgrading blockchain database")
139142

140143
chain, chainDb := utils.MakeChain(ctx)
@@ -163,9 +166,10 @@ func upgradeDB(ctx *cli.Context) {
163166
os.Remove(exportFile)
164167
glog.Infoln("Import finished")
165168
}
169+
return nil
166170
}
167171

168-
func dump(ctx *cli.Context) {
172+
func dump(ctx *cli.Context) error {
169173
chain, chainDb := utils.MakeChain(ctx)
170174
for _, arg := range ctx.Args() {
171175
var block *types.Block
@@ -182,12 +186,12 @@ func dump(ctx *cli.Context) {
182186
state, err := state.New(block.Root(), chainDb)
183187
if err != nil {
184188
utils.Fatalf("could not create new state: %v", err)
185-
return
186189
}
187190
fmt.Printf("%s\n", state.Dump())
188191
}
189192
}
190193
chainDb.Close()
194+
return nil
191195
}
192196

193197
// hashish returns true for strings that look like hashes.

cmd/geth/consolecmd.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
6060

6161
// localConsole starts a new geth node, attaching a JavaScript console to it at the
6262
// same time.
63-
func localConsole(ctx *cli.Context) {
63+
func localConsole(ctx *cli.Context) error {
6464
// Create and start the node based on the CLI flags
6565
node := utils.MakeSystemNode(clientIdentifier, verString, relConfig, makeDefaultExtra(), ctx)
6666
startNode(ctx, node)
@@ -86,16 +86,18 @@ func localConsole(ctx *cli.Context) {
8686
// If only a short execution was requested, evaluate and return
8787
if script := ctx.GlobalString(utils.ExecFlag.Name); script != "" {
8888
console.Evaluate(script)
89-
return
89+
return nil
9090
}
9191
// Otherwise print the welcome screen and enter interactive mode
9292
console.Welcome()
9393
console.Interactive()
94+
95+
return nil
9496
}
9597

9698
// remoteConsole will connect to a remote geth instance, attaching a JavaScript
9799
// console to it.
98-
func remoteConsole(ctx *cli.Context) {
100+
func remoteConsole(ctx *cli.Context) error {
99101
// Attach to a remotely running geth instance and start the JavaScript console
100102
client, err := utils.NewRemoteRPCClient(ctx)
101103
if err != nil {
@@ -116,17 +118,19 @@ func remoteConsole(ctx *cli.Context) {
116118
// If only a short execution was requested, evaluate and return
117119
if script := ctx.GlobalString(utils.ExecFlag.Name); script != "" {
118120
console.Evaluate(script)
119-
return
121+
return nil
120122
}
121123
// Otherwise print the welcome screen and enter interactive mode
122124
console.Welcome()
123125
console.Interactive()
126+
127+
return nil
124128
}
125129

126130
// ephemeralConsole starts a new geth node, attaches an ephemeral JavaScript
127131
// console to it, and each of the files specified as arguments and tears the
128132
// everything down.
129-
func ephemeralConsole(ctx *cli.Context) {
133+
func ephemeralConsole(ctx *cli.Context) error {
130134
// Create and start the node based on the CLI flags
131135
node := utils.MakeSystemNode(clientIdentifier, verString, relConfig, makeDefaultExtra(), ctx)
132136
startNode(ctx, node)
@@ -164,4 +168,6 @@ func ephemeralConsole(ctx *cli.Context) {
164168
os.Exit(0)
165169
}()
166170
console.Stop(true)
171+
172+
return nil
167173
}

cmd/geth/main.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,17 @@ func makeDefaultExtra() []byte {
271271
// geth is the main entry point into the system if no special subcommand is ran.
272272
// It creates a default node based on the command line arguments and runs it in
273273
// blocking mode, waiting for it to be shut down.
274-
func geth(ctx *cli.Context) {
274+
func geth(ctx *cli.Context) error {
275275
node := utils.MakeSystemNode(clientIdentifier, verString, relConfig, makeDefaultExtra(), ctx)
276276
startNode(ctx, node)
277277
node.Wait()
278+
279+
return nil
278280
}
279281

280282
// initGenesis will initialise the given JSON format genesis file and writes it as
281283
// the zero'd block (i.e. genesis) or will fail hard if it can't succeed.
282-
func initGenesis(ctx *cli.Context) {
284+
func initGenesis(ctx *cli.Context) error {
283285
genesisPath := ctx.Args().First()
284286
if len(genesisPath) == 0 {
285287
utils.Fatalf("must supply path to genesis JSON file")
@@ -300,6 +302,7 @@ func initGenesis(ctx *cli.Context) {
300302
utils.Fatalf("failed to write genesis block: %v", err)
301303
}
302304
glog.V(logger.Info).Infof("successfully wrote genesis block and/or chain rule set: %x", block.Hash())
305+
return nil
303306
}
304307

305308
// startNode boots up the system node and all registered protocols, after which
@@ -331,7 +334,7 @@ func startNode(ctx *cli.Context, stack *node.Node) {
331334
}
332335
}
333336

334-
func makedag(ctx *cli.Context) {
337+
func makedag(ctx *cli.Context) error {
335338
args := ctx.Args()
336339
wrongArgs := func() {
337340
utils.Fatalf(`Usage: geth makedag <block number> <outputdir>`)
@@ -358,13 +361,15 @@ func makedag(ctx *cli.Context) {
358361
default:
359362
wrongArgs()
360363
}
364+
return nil
361365
}
362366

363-
func gpuinfo(ctx *cli.Context) {
367+
func gpuinfo(ctx *cli.Context) error {
364368
eth.PrintOpenCLDevices()
369+
return nil
365370
}
366371

367-
func gpubench(ctx *cli.Context) {
372+
func gpubench(ctx *cli.Context) error {
368373
args := ctx.Args()
369374
wrongArgs := func() {
370375
utils.Fatalf(`Usage: geth gpubench <gpu number>`)
@@ -381,9 +386,10 @@ func gpubench(ctx *cli.Context) {
381386
default:
382387
wrongArgs()
383388
}
389+
return nil
384390
}
385391

386-
func version(c *cli.Context) {
392+
func version(c *cli.Context) error {
387393
fmt.Println(clientIdentifier)
388394
fmt.Println("Version:", verString)
389395
fmt.Println("Protocol Versions:", eth.ProtocolVersions)
@@ -392,4 +398,6 @@ func version(c *cli.Context) {
392398
fmt.Println("OS:", runtime.GOOS)
393399
fmt.Printf("GOPATH=%s\n", os.Getenv("GOPATH"))
394400
fmt.Printf("GOROOT=%s\n", runtime.GOROOT())
401+
402+
return nil
395403
}

cmd/geth/monitorcmd.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ to display multiple metrics simultaneously.
6767
)
6868

6969
// monitor starts a terminal UI based monitoring tool for the requested metrics.
70-
func monitor(ctx *cli.Context) {
70+
func monitor(ctx *cli.Context) error {
7171
var (
7272
client rpc.Client
7373
err error
@@ -154,6 +154,7 @@ func monitor(ctx *cli.Context) {
154154
}
155155
}()
156156
termui.Loop()
157+
return nil
157158
}
158159

159160
// retrieveMetrics contacts the attached geth node and retrieves the entire set

cmd/geth/run_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ type testgeth struct {
5858
func init() {
5959
// Run the app if we're the child process for runGeth.
6060
if os.Getenv("GETH_TEST_CHILD") != "" {
61-
app.RunAndExitOnError()
61+
if err := app.Run(os.Args); err != nil {
62+
fmt.Fprintln(os.Stderr, err)
63+
os.Exit(1)
64+
}
6265
os.Exit(0)
6366
}
6467
}

0 commit comments

Comments
 (0)