Skip to content

Commit 881df0e

Browse files
authored
Merge pull request #14413 from bas-vk/cli-chain-mngt
Migrate remaining flags/command to new style
2 parents 1c2f6f5 + 81d6ec9 commit 881df0e

File tree

8 files changed

+129
-94
lines changed

8 files changed

+129
-94
lines changed

cmd/geth/bugcmd.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ import (
2929
"github.com/ethereum/go-ethereum/cmd/internal/browser"
3030
"github.com/ethereum/go-ethereum/params"
3131

32+
"github.com/ethereum/go-ethereum/cmd/utils"
3233
cli "gopkg.in/urfave/cli.v1"
3334
)
3435

3536
var bugCommand = cli.Command{
36-
Action: reportBug,
37+
Action: utils.MigrateFlags(reportBug),
3738
Name: "bug",
3839
Usage: "opens a window to report a bug on the geth repo",
3940
ArgsUsage: " ",

cmd/geth/chaincmd.go

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,63 +40,84 @@ import (
4040

4141
var (
4242
initCommand = cli.Command{
43-
Action: initGenesis,
43+
Action: utils.MigrateFlags(initGenesis),
4444
Name: "init",
4545
Usage: "Bootstrap and initialize a new genesis block",
4646
ArgsUsage: "<genesisPath>",
47-
Category: "BLOCKCHAIN COMMANDS",
47+
Flags: []cli.Flag{
48+
utils.DataDirFlag,
49+
utils.LightModeFlag,
50+
},
51+
Category: "BLOCKCHAIN COMMANDS",
4852
Description: `
4953
The init command initializes a new genesis block and definition for the network.
5054
This is a destructive action and changes the network in which you will be
5155
participating.
52-
`,
56+
57+
It expects the genesis file as argument.`,
5358
}
5459
importCommand = cli.Command{
55-
Action: importChain,
60+
Action: utils.MigrateFlags(importChain),
5661
Name: "import",
5762
Usage: "Import a blockchain file",
5863
ArgsUsage: "<filename> (<filename 2> ... <filename N>) ",
59-
Category: "BLOCKCHAIN COMMANDS",
64+
Flags: []cli.Flag{
65+
utils.DataDirFlag,
66+
utils.CacheFlag,
67+
utils.LightModeFlag,
68+
},
69+
Category: "BLOCKCHAIN COMMANDS",
6070
Description: `
6171
The import command imports blocks from an RLP-encoded form. The form can be one file
6272
with several RLP-encoded blocks, or several files can be used.
63-
If only one file is used, import error will result in failure. If several files are used,
64-
processing will proceed even if an individual RLP-file import failure occurs.
65-
`,
73+
74+
If only one file is used, import error will result in failure. If several files are used,
75+
processing will proceed even if an individual RLP-file import failure occurs.`,
6676
}
6777
exportCommand = cli.Command{
68-
Action: exportChain,
78+
Action: utils.MigrateFlags(exportChain),
6979
Name: "export",
7080
Usage: "Export blockchain into file",
7181
ArgsUsage: "<filename> [<blockNumFirst> <blockNumLast>]",
72-
Category: "BLOCKCHAIN COMMANDS",
82+
Flags: []cli.Flag{
83+
utils.DataDirFlag,
84+
utils.CacheFlag,
85+
utils.LightModeFlag,
86+
},
87+
Category: "BLOCKCHAIN COMMANDS",
7388
Description: `
7489
Requires a first argument of the file to write to.
7590
Optional second and third arguments control the first and
7691
last block to write. In this mode, the file will be appended
77-
if already existing.
78-
`,
92+
if already existing.`,
7993
}
8094
removedbCommand = cli.Command{
81-
Action: removeDB,
95+
Action: utils.MigrateFlags(removeDB),
8296
Name: "removedb",
8397
Usage: "Remove blockchain and state databases",
8498
ArgsUsage: " ",
85-
Category: "BLOCKCHAIN COMMANDS",
99+
Flags: []cli.Flag{
100+
utils.DataDirFlag,
101+
utils.LightModeFlag,
102+
},
103+
Category: "BLOCKCHAIN COMMANDS",
86104
Description: `
87-
TODO: Please write this
88-
`,
105+
Remove blockchain and state databases`,
89106
}
90107
dumpCommand = cli.Command{
91-
Action: dump,
108+
Action: utils.MigrateFlags(dump),
92109
Name: "dump",
93110
Usage: "Dump a specific block from storage",
94111
ArgsUsage: "[<blockHash> | <blockNum>]...",
95-
Category: "BLOCKCHAIN COMMANDS",
112+
Flags: []cli.Flag{
113+
utils.DataDirFlag,
114+
utils.CacheFlag,
115+
utils.LightModeFlag,
116+
},
117+
Category: "BLOCKCHAIN COMMANDS",
96118
Description: `
97119
The arguments are interpreted as block numbers or hashes.
98-
Use "ethereum dump 0" to dump the genesis block.
99-
`,
120+
Use "ethereum dump 0" to dump the genesis block.`,
100121
}
101122
)
102123

cmd/geth/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ import (
3838

3939
var (
4040
dumpConfigCommand = cli.Command{
41-
Action: dumpConfig,
41+
Action: utils.MigrateFlags(dumpConfig),
4242
Name: "dumpconfig",
4343
Usage: "Show configuration values",
4444
ArgsUsage: "",
45+
Flags: append(nodeFlags, rpcFlags...),
4546
Category: "MISCELLANEOUS COMMANDS",
4647
Description: `The dumpconfig command shows configuration values.`,
4748
}

cmd/geth/consolecmd.go

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,42 +28,47 @@ import (
2828
"gopkg.in/urfave/cli.v1"
2929
)
3030

31+
var (
32+
consoleFlags = []cli.Flag{utils.JSpathFlag, utils.ExecFlag, utils.PreloadJSFlag}
33+
)
34+
3135
var (
3236
consoleCommand = cli.Command{
33-
Action: localConsole,
34-
Name: "console",
35-
Usage: "Start an interactive JavaScript environment",
36-
ArgsUsage: "", // TODO: Write this!
37-
Category: "CONSOLE COMMANDS",
37+
Action: utils.MigrateFlags(localConsole),
38+
Name: "console",
39+
Usage: "Start an interactive JavaScript environment",
40+
Flags: append(append(nodeFlags, rpcFlags...), consoleFlags...),
41+
Category: "CONSOLE COMMANDS",
3842
Description: `
3943
The Geth console is an interactive shell for the JavaScript runtime environment
4044
which exposes a node admin interface as well as the Ðapp JavaScript API.
41-
See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Console
42-
`,
45+
See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Console.`,
4346
}
47+
4448
attachCommand = cli.Command{
45-
Action: remoteConsole,
49+
Action: utils.MigrateFlags(remoteConsole),
4650
Name: "attach",
4751
Usage: "Start an interactive JavaScript environment (connect to node)",
48-
ArgsUsage: "", // TODO: Write this!
52+
ArgsUsage: "[endpoint]",
53+
Flags: append(consoleFlags, utils.DataDirFlag),
4954
Category: "CONSOLE COMMANDS",
5055
Description: `
5156
The Geth console is an interactive shell for the JavaScript runtime environment
5257
which exposes a node admin interface as well as the Ðapp JavaScript API.
5358
See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Console.
54-
This command allows to open a console on a running geth node.
55-
`,
59+
This command allows to open a console on a running geth node.`,
5660
}
61+
5762
javascriptCommand = cli.Command{
58-
Action: ephemeralConsole,
63+
Action: utils.MigrateFlags(ephemeralConsole),
5964
Name: "js",
6065
Usage: "Execute the specified JavaScript files",
61-
ArgsUsage: "", // TODO: Write this!
66+
ArgsUsage: "<jsfile> [jsfile...]",
67+
Flags: append(nodeFlags, consoleFlags...),
6268
Category: "CONSOLE COMMANDS",
6369
Description: `
6470
The JavaScript VM exposes a node admin interface as well as the Ðapp
65-
JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Console
66-
`,
71+
JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Console`,
6772
}
6873
)
6974

@@ -81,11 +86,12 @@ func localConsole(ctx *cli.Context) error {
8186
utils.Fatalf("Failed to attach to the inproc geth: %v", err)
8287
}
8388
config := console.Config{
84-
DataDir: node.DataDir(),
89+
DataDir: utils.MakeDataDir(ctx),
8590
DocRoot: ctx.GlobalString(utils.JSpathFlag.Name),
8691
Client: client,
8792
Preload: utils.MakeConsolePreloads(ctx),
8893
}
94+
8995
console, err := console.New(config)
9096
if err != nil {
9197
utils.Fatalf("Failed to start the JavaScript console: %v", err)
@@ -118,17 +124,18 @@ func remoteConsole(ctx *cli.Context) error {
118124
Client: client,
119125
Preload: utils.MakeConsolePreloads(ctx),
120126
}
127+
121128
console, err := console.New(config)
122129
if err != nil {
123130
utils.Fatalf("Failed to start the JavaScript console: %v", err)
124131
}
125132
defer console.Stop(false)
126133

127-
// If only a short execution was requested, evaluate and return
128134
if script := ctx.GlobalString(utils.ExecFlag.Name); script != "" {
129135
console.Evaluate(script)
130136
return nil
131137
}
138+
132139
// Otherwise print the welcome screen and enter interactive mode
133140
console.Welcome()
134141
console.Interactive()
@@ -151,7 +158,7 @@ func dialRPC(endpoint string) (*rpc.Client, error) {
151158
}
152159

153160
// ephemeralConsole starts a new geth node, attaches an ephemeral JavaScript
154-
// console to it, and each of the files specified as arguments and tears the
161+
// console to it, executes each of the files specified as arguments and tears
155162
// everything down.
156163
func ephemeralConsole(ctx *cli.Context) error {
157164
// Create and start the node based on the CLI flags
@@ -165,11 +172,12 @@ func ephemeralConsole(ctx *cli.Context) error {
165172
utils.Fatalf("Failed to attach to the inproc geth: %v", err)
166173
}
167174
config := console.Config{
168-
DataDir: node.DataDir(),
175+
DataDir: utils.MakeDataDir(ctx),
169176
DocRoot: ctx.GlobalString(utils.JSpathFlag.Name),
170177
Client: client,
171178
Preload: utils.MakeConsolePreloads(ctx),
172179
}
180+
173181
console, err := console.New(config)
174182
if err != nil {
175183
utils.Fatalf("Failed to start the JavaScript console: %v", err)

cmd/geth/main.go

Lines changed: 51 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -49,39 +49,8 @@ var (
4949
relOracle = common.HexToAddress("0xfa7b9770ca4cb04296cac84f37736d4041251cdf")
5050
// The app that holds all commands and flags.
5151
app = utils.NewApp(gitCommit, "the go-ethereum command line interface")
52-
)
53-
54-
func init() {
55-
// Initialize the CLI app and start Geth
56-
app.Action = geth
57-
app.HideVersion = true // we have a command to print the version
58-
app.Copyright = "Copyright 2013-2017 The go-ethereum Authors"
59-
app.Commands = []cli.Command{
60-
// See chaincmd.go:
61-
initCommand,
62-
importCommand,
63-
exportCommand,
64-
removedbCommand,
65-
dumpCommand,
66-
// See monitorcmd.go:
67-
monitorCommand,
68-
// See accountcmd.go:
69-
accountCommand,
70-
walletCommand,
71-
// See consolecmd.go:
72-
consoleCommand,
73-
attachCommand,
74-
javascriptCommand,
75-
// See misccmd.go:
76-
makedagCommand,
77-
versionCommand,
78-
bugCommand,
79-
licenseCommand,
80-
// See config.go
81-
dumpConfigCommand,
82-
}
83-
84-
app.Flags = []cli.Flag{
52+
// flags that configure the node
53+
nodeFlags = []cli.Flag{
8554
utils.IdentityFlag,
8655
utils.UnlockedAccountFlag,
8756
utils.PasswordFileFlag,
@@ -103,7 +72,6 @@ func init() {
10372
utils.LightKDFFlag,
10473
utils.CacheFlag,
10574
utils.TrieCacheGenFlag,
106-
utils.JSpathFlag,
10775
utils.ListenPortFlag,
10876
utils.MaxPeersFlag,
10977
utils.MaxPendingPeersFlag,
@@ -118,19 +86,6 @@ func init() {
11886
utils.NetrestrictFlag,
11987
utils.NodeKeyFileFlag,
12088
utils.NodeKeyHexFlag,
121-
utils.RPCEnabledFlag,
122-
utils.RPCListenAddrFlag,
123-
utils.RPCPortFlag,
124-
utils.RPCApiFlag,
125-
utils.WSEnabledFlag,
126-
utils.WSListenAddrFlag,
127-
utils.WSPortFlag,
128-
utils.WSApiFlag,
129-
utils.WSAllowedOriginsFlag,
130-
utils.IPCDisabledFlag,
131-
utils.IPCPathFlag,
132-
utils.ExecFlag,
133-
utils.PreloadJSFlag,
13489
utils.WhisperEnabledFlag,
13590
utils.DevModeFlag,
13691
utils.TestNetFlag,
@@ -146,6 +101,55 @@ func init() {
146101
utils.ExtraDataFlag,
147102
configFileFlag,
148103
}
104+
105+
rpcFlags = []cli.Flag{
106+
utils.RPCEnabledFlag,
107+
utils.RPCListenAddrFlag,
108+
utils.RPCPortFlag,
109+
utils.RPCApiFlag,
110+
utils.WSEnabledFlag,
111+
utils.WSListenAddrFlag,
112+
utils.WSPortFlag,
113+
utils.WSApiFlag,
114+
utils.WSAllowedOriginsFlag,
115+
utils.IPCDisabledFlag,
116+
utils.IPCPathFlag,
117+
}
118+
)
119+
120+
func init() {
121+
// Initialize the CLI app and start Geth
122+
app.Action = geth
123+
app.HideVersion = true // we have a command to print the version
124+
app.Copyright = "Copyright 2013-2017 The go-ethereum Authors"
125+
app.Commands = []cli.Command{
126+
// See chaincmd.go:
127+
initCommand,
128+
importCommand,
129+
exportCommand,
130+
removedbCommand,
131+
dumpCommand,
132+
// See monitorcmd.go:
133+
monitorCommand,
134+
// See accountcmd.go:
135+
accountCommand,
136+
walletCommand,
137+
// See consolecmd.go:
138+
consoleCommand,
139+
attachCommand,
140+
javascriptCommand,
141+
// See misccmd.go:
142+
makedagCommand,
143+
versionCommand,
144+
bugCommand,
145+
licenseCommand,
146+
// See config.go
147+
dumpConfigCommand,
148+
}
149+
150+
app.Flags = append(app.Flags, nodeFlags...)
151+
app.Flags = append(app.Flags, rpcFlags...)
152+
app.Flags = append(app.Flags, consoleFlags...)
149153
app.Flags = append(app.Flags, debug.Flags...)
150154

151155
app.Before = func(ctx *cli.Context) error {

0 commit comments

Comments
 (0)