From 2a0528303fb18dcc6799405d62a3a6f19da20b4a Mon Sep 17 00:00:00 2001 From: Bas van Kervel Date: Sat, 13 Jun 2015 19:02:46 +0200 Subject: [PATCH 1/2] added batch mode to console --- cmd/console/js.go | 24 +++++++++++++++++++++++- cmd/console/main.go | 11 +++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/cmd/console/js.go b/cmd/console/js.go index a5fdaacc2..bda58be4d 100644 --- a/cmd/console/js.go +++ b/cmd/console/js.go @@ -30,6 +30,7 @@ import ( "sort" + "github.com/codegangsta/cli" "github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/common/docserver" re "github.com/ethereum/go-ethereum/jsre" @@ -329,7 +330,28 @@ func (self *jsre) welcome(ipcpath string) { } } -func (self *jsre) interactive() { +func (self *jsre) batch(args cli.Args) { + statement := strings.Join(args, " ") + + val, err := self.re.Run(statement) + + if err != nil { + fmt.Printf("error: %v", err) + } else if val.IsDefined() { + fmt.Printf("%v", val) + } + + if self.atexit != nil { + self.atexit() + } + + self.re.Stop(false) + +} + +func (self *jsre) interactive(ipcpath string) { + self.welcome(ipcpath) + // Read input lines. prompt := make(chan string) inputln := make(chan string) diff --git a/cmd/console/main.go b/cmd/console/main.go index e8dd412ba..00a9ca9c4 100644 --- a/cmd/console/main.go +++ b/cmd/console/main.go @@ -40,7 +40,7 @@ const ( var ( gitCommit string // set via linker flag nodeNameVersion string - app = utils.NewApp(Version, "the ether console") + app = utils.NewApp(Version, "the geth console") ) func init() { @@ -93,8 +93,11 @@ func main() { func run(ctx *cli.Context) { jspath := ctx.GlobalString(utils.JSpathFlag.Name) ipcpath := utils.IpcSocketPath(ctx) - repl := newJSRE(jspath, ipcpath) - repl.welcome(ipcpath) - repl.interactive() + + if ctx.Args().Present() { + repl.batch(ctx.Args()) + } else { + repl.interactive(ipcpath) + } } From f06f220c7c8de5fe4a08cf7d6d9531a0a564ee12 Mon Sep 17 00:00:00 2001 From: Bas van Kervel Date: Mon, 15 Jun 2015 16:33:36 +0200 Subject: [PATCH 2/2] added printing support for objects --- cmd/console/js.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/console/js.go b/cmd/console/js.go index bda58be4d..15ea9bedd 100644 --- a/cmd/console/js.go +++ b/cmd/console/js.go @@ -332,11 +332,13 @@ func (self *jsre) welcome(ipcpath string) { func (self *jsre) batch(args cli.Args) { statement := strings.Join(args, " ") - val, err := self.re.Run(statement) if err != nil { fmt.Printf("error: %v", err) + } else if val.IsDefined() && val.IsObject() { + obj, _ := self.re.Get("ret_result") + fmt.Printf("%v", obj) } else if val.IsDefined() { fmt.Printf("%v", val) } @@ -346,7 +348,6 @@ func (self *jsre) batch(args cli.Args) { } self.re.Stop(false) - } func (self *jsre) interactive(ipcpath string) {