Skip to content

Commit 502a2bd

Browse files
committed
cmd/geth: reorganise console/attach commands/flags
1 parent 8b517d7 commit 502a2bd

File tree

3 files changed

+79
-67
lines changed

3 files changed

+79
-67
lines changed

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 {

cmd/utils/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ var (
331331
}
332332
ExecFlag = cli.StringFlag{
333333
Name: "exec",
334-
Usage: "Execute JavaScript statement (only in combination with console/attach)",
334+
Usage: "Execute JavaScript statement",
335335
}
336336
PreloadJSFlag = cli.StringFlag{
337337
Name: "preload",

0 commit comments

Comments
 (0)