diff options
author | Felix Lange <fjl@twurst.com> | 2016-04-26 16:39:19 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2016-04-26 16:39:19 +0800 |
commit | 3d6d828caf2dbf2e7ceeeb6f0d38c3b654aefcd2 (patch) | |
tree | e2f449e08d17977cc47331f02c43a28a11e78f10 /cmd/geth/main.go | |
parent | 70b8b54cd2413fb01e279890b2ddb5eb9bc227c2 (diff) | |
parent | 87ae0df476cf6b413795ee54207e8ec86e178dbc (diff) | |
download | go-tangerine-3d6d828caf2dbf2e7ceeeb6f0d38c3b654aefcd2.tar go-tangerine-3d6d828caf2dbf2e7ceeeb6f0d38c3b654aefcd2.tar.gz go-tangerine-3d6d828caf2dbf2e7ceeeb6f0d38c3b654aefcd2.tar.bz2 go-tangerine-3d6d828caf2dbf2e7ceeeb6f0d38c3b654aefcd2.tar.lz go-tangerine-3d6d828caf2dbf2e7ceeeb6f0d38c3b654aefcd2.tar.xz go-tangerine-3d6d828caf2dbf2e7ceeeb6f0d38c3b654aefcd2.tar.zst go-tangerine-3d6d828caf2dbf2e7ceeeb6f0d38c3b654aefcd2.zip |
Merge pull request #2478 from fjl/geth-js-tweak
cmd/geth, jsre: improve the js command
Diffstat (limited to 'cmd/geth/main.go')
-rw-r--r-- | cmd/geth/main.go | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 6ab4ed45b..a43daba2f 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -21,6 +21,7 @@ import ( "fmt" "io/ioutil" "os" + "os/signal" "path/filepath" "runtime" "strconv" @@ -353,7 +354,7 @@ func console(ctx *cli.Context) { // preload user defined JS files into the console err = repl.preloadJSFiles(ctx) if err != nil { - utils.Fatalf("unable to preload JS file %v", err) + utils.Fatalf("%v", err) } // in case the exec flag holds a JS statement execute it and return @@ -372,6 +373,7 @@ func execScripts(ctx *cli.Context) { // Create and start the node based on the CLI flags node := utils.MakeSystemNode(ClientIdentifier, nodeNameVersion, makeDefaultExtra(), ctx) startNode(ctx, node) + defer node.Stop() // Attach to the newly started node and execute the given scripts client, err := node.Attach() @@ -383,10 +385,24 @@ func execScripts(ctx *cli.Context) { ctx.GlobalString(utils.RPCCORSDomainFlag.Name), client, false) + // Run all given files. for _, file := range ctx.Args() { - repl.exec(file) + if err = repl.re.Exec(file); err != nil { + break + } } - node.Stop() + if err != nil { + utils.Fatalf("JavaScript Error: %v", jsErrorString(err)) + } + // JS files loaded successfully. + // Wait for pending callbacks, but stop for Ctrl-C. + abort := make(chan os.Signal, 1) + signal.Notify(abort, os.Interrupt) + go func() { + <-abort + repl.re.Stop(false) + }() + repl.re.Stop(true) } // startNode boots up the system node and all registered protocols, after which |