diff options
author | Bas van Kervel <basvankervel@gmail.com> | 2017-05-03 18:26:09 +0800 |
---|---|---|
committer | Bas van Kervel <basvankervel@gmail.com> | 2017-05-03 20:33:07 +0800 |
commit | 502a2bd69ffa1ff49a394740d904df64c85e3ade (patch) | |
tree | bbe54706f84a727a890e4a633c1b07dc8b5efee8 /cmd/geth/consolecmd.go | |
parent | 8b517d7f00f5334a92b8796e11f4c4f71d884cbd (diff) | |
download | go-tangerine-502a2bd69ffa1ff49a394740d904df64c85e3ade.tar go-tangerine-502a2bd69ffa1ff49a394740d904df64c85e3ade.tar.gz go-tangerine-502a2bd69ffa1ff49a394740d904df64c85e3ade.tar.bz2 go-tangerine-502a2bd69ffa1ff49a394740d904df64c85e3ade.tar.lz go-tangerine-502a2bd69ffa1ff49a394740d904df64c85e3ade.tar.xz go-tangerine-502a2bd69ffa1ff49a394740d904df64c85e3ade.tar.zst go-tangerine-502a2bd69ffa1ff49a394740d904df64c85e3ade.zip |
cmd/geth: reorganise console/attach commands/flags
Diffstat (limited to 'cmd/geth/consolecmd.go')
-rw-r--r-- | cmd/geth/consolecmd.go | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/cmd/geth/consolecmd.go b/cmd/geth/consolecmd.go index b1c435e00..6efdbbf57 100644 --- a/cmd/geth/consolecmd.go +++ b/cmd/geth/consolecmd.go @@ -29,41 +29,46 @@ import ( ) var ( + consoleFlags = []cli.Flag{utils.JSpathFlag, utils.ExecFlag, utils.PreloadJSFlag} +) + +var ( consoleCommand = cli.Command{ - Action: localConsole, - Name: "console", - Usage: "Start an interactive JavaScript environment", - ArgsUsage: "", // TODO: Write this! - Category: "CONSOLE COMMANDS", + Action: utils.MigrateFlags(localConsole), + Name: "console", + Usage: "Start an interactive JavaScript environment", + Flags: append(append(nodeFlags, rpcFlags...), consoleFlags...), + Category: "CONSOLE COMMANDS", Description: ` The Geth console is an interactive shell for the JavaScript runtime environment which exposes a node admin interface as well as the Ðapp JavaScript API. -See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Console -`, +See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Console.`, } + attachCommand = cli.Command{ - Action: remoteConsole, + Action: utils.MigrateFlags(remoteConsole), Name: "attach", Usage: "Start an interactive JavaScript environment (connect to node)", - ArgsUsage: "", // TODO: Write this! + ArgsUsage: "[endpoint]", + Flags: append(consoleFlags, utils.DataDirFlag), Category: "CONSOLE COMMANDS", Description: ` The Geth console is an interactive shell for the JavaScript runtime environment which exposes a node admin interface as well as the Ðapp JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Console. -This command allows to open a console on a running geth node. -`, +This command allows to open a console on a running geth node.`, } + javascriptCommand = cli.Command{ - Action: ephemeralConsole, + Action: utils.MigrateFlags(ephemeralConsole), Name: "js", Usage: "Execute the specified JavaScript files", - ArgsUsage: "", // TODO: Write this! + ArgsUsage: "<jsfile> [jsfile...]", + Flags: append(nodeFlags, consoleFlags...), Category: "CONSOLE COMMANDS", Description: ` The JavaScript VM exposes a node admin interface as well as the Ðapp -JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Console -`, +JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Console`, } ) @@ -81,11 +86,12 @@ func localConsole(ctx *cli.Context) error { utils.Fatalf("Failed to attach to the inproc geth: %v", err) } config := console.Config{ - DataDir: node.DataDir(), + DataDir: utils.MakeDataDir(ctx), DocRoot: ctx.GlobalString(utils.JSpathFlag.Name), Client: client, Preload: utils.MakeConsolePreloads(ctx), } + console, err := console.New(config) if err != nil { utils.Fatalf("Failed to start the JavaScript console: %v", err) @@ -118,17 +124,18 @@ func remoteConsole(ctx *cli.Context) error { Client: client, Preload: utils.MakeConsolePreloads(ctx), } + console, err := console.New(config) if err != nil { utils.Fatalf("Failed to start the JavaScript console: %v", err) } defer console.Stop(false) - // If only a short execution was requested, evaluate and return if script := ctx.GlobalString(utils.ExecFlag.Name); script != "" { console.Evaluate(script) return nil } + // Otherwise print the welcome screen and enter interactive mode console.Welcome() console.Interactive() @@ -151,7 +158,7 @@ func dialRPC(endpoint string) (*rpc.Client, error) { } // ephemeralConsole starts a new geth node, attaches an ephemeral JavaScript -// console to it, and each of the files specified as arguments and tears the +// console to it, executes each of the files specified as arguments and tears // everything down. func ephemeralConsole(ctx *cli.Context) error { // Create and start the node based on the CLI flags @@ -165,11 +172,12 @@ func ephemeralConsole(ctx *cli.Context) error { utils.Fatalf("Failed to attach to the inproc geth: %v", err) } config := console.Config{ - DataDir: node.DataDir(), + DataDir: utils.MakeDataDir(ctx), DocRoot: ctx.GlobalString(utils.JSpathFlag.Name), Client: client, Preload: utils.MakeConsolePreloads(ctx), } + console, err := console.New(config) if err != nil { utils.Fatalf("Failed to start the JavaScript console: %v", err) |