diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2016-04-12 17:00:42 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2016-04-12 17:00:42 +0800 |
commit | 934f587bd5c38a36e8b8c8647a9e600d1751ff2f (patch) | |
tree | 342555f160d5141b9e4a44d0d4504edb0337dce8 /cmd | |
parent | e456451a89042fd477f8c05de25a1a1265e4b65b (diff) | |
parent | 3c5329599c6a07176fb80848f8592c5f90944a31 (diff) | |
download | dexon-934f587bd5c38a36e8b8c8647a9e600d1751ff2f.tar dexon-934f587bd5c38a36e8b8c8647a9e600d1751ff2f.tar.gz dexon-934f587bd5c38a36e8b8c8647a9e600d1751ff2f.tar.bz2 dexon-934f587bd5c38a36e8b8c8647a9e600d1751ff2f.tar.lz dexon-934f587bd5c38a36e8b8c8647a9e600d1751ff2f.tar.xz dexon-934f587bd5c38a36e8b8c8647a9e600d1751ff2f.tar.zst dexon-934f587bd5c38a36e8b8c8647a9e600d1751ff2f.zip |
Merge pull request #2431 from bas-vk/js-preload
cmd/geth: add JS preload parameter
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/geth/js.go | 18 | ||||
-rw-r--r-- | cmd/geth/main.go | 15 | ||||
-rw-r--r-- | cmd/geth/usage.go | 1 | ||||
-rw-r--r-- | cmd/utils/flags.go | 4 |
4 files changed, 38 insertions, 0 deletions
diff --git a/cmd/geth/js.go b/cmd/geth/js.go index a4b14d7b1..b01fd7e36 100644 --- a/cmd/geth/js.go +++ b/cmd/geth/js.go @@ -27,6 +27,7 @@ import ( "sort" "strings" + "github.com/codegangsta/cli" "github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/registrar" @@ -331,6 +332,23 @@ func (self *jsre) UnlockAccount(addr []byte) bool { } } +// preloadJSFiles loads JS files that the user has specified with ctx.PreLoadJSFlag into +// the JSRE. If not all files could be loaded it will return an error describing the error. +func (self *jsre) preloadJSFiles(ctx *cli.Context) error { + if ctx.GlobalString(utils.PreLoadJSFlag.Name) != "" { + assetPath := ctx.GlobalString(utils.JSpathFlag.Name) + jsFiles := strings.Split(ctx.GlobalString(utils.PreLoadJSFlag.Name), ",") + for _, file := range jsFiles { + filename := common.AbsolutePath(assetPath, strings.TrimSpace(file)) + if err := self.re.Exec(filename); err != nil { + return fmt.Errorf("%s: %v", file, err) + } + } + } + return nil +} + +// exec executes the JS file with the given filename and stops the JSRE func (self *jsre) exec(filename string) error { if err := self.re.Exec(filename); err != nil { self.re.Stop(false) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 645743c13..c0a7ba318 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -331,6 +331,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso utils.IPCApiFlag, utils.IPCPathFlag, utils.ExecFlag, + utils.PreLoadJSFlag, utils.WhisperEnabledFlag, utils.DevModeFlag, utils.TestNetFlag, @@ -427,6 +428,13 @@ func attach(ctx *cli.Context) { true, ) + // preload user defined JS files into the console + err = repl.preloadJSFiles(ctx) + if err != nil { + utils.Fatalf("unable to preload JS file %v", err) + } + + // in case the exec flag holds a JS statement execute it and return if ctx.GlobalString(utils.ExecFlag.Name) != "" { repl.batch(ctx.GlobalString(utils.ExecFlag.Name)) } else { @@ -477,6 +485,13 @@ func console(ctx *cli.Context) { ctx.GlobalString(utils.RPCCORSDomainFlag.Name), client, true) + // preload user defined JS files into the console + err = repl.preloadJSFiles(ctx) + if err != nil { + utils.Fatalf("unable to preload JS file %v", err) + } + + // in case the exec flag holds a JS statement execute it and return if script := ctx.GlobalString(utils.ExecFlag.Name); script != "" { repl.batch(script) } else { diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go index e2adf7305..5d36b5b1d 100644 --- a/cmd/geth/usage.go +++ b/cmd/geth/usage.go @@ -101,6 +101,7 @@ var AppHelpFlagGroups = []flagGroup{ utils.RPCCORSDomainFlag, utils.JSpathFlag, utils.ExecFlag, + utils.PreLoadJSFlag, }, }, { diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index a2927108f..d478bb095 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -296,6 +296,10 @@ var ( Name: "exec", Usage: "Execute JavaScript statement (only in combination with console/attach)", } + PreLoadJSFlag = cli.StringFlag{ + Name: "preload", + Usage: "Comma separated list of JavaScript files to preload into the console", + } // Network Settings MaxPeersFlag = cli.IntFlag{ |