diff options
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/ethtest/main.go | 6 | ||||
-rw-r--r-- | cmd/evm/main.go | 5 | ||||
-rw-r--r-- | cmd/geth/accountcmd.go | 19 | ||||
-rw-r--r-- | cmd/geth/chaincmd.go | 18 | ||||
-rw-r--r-- | cmd/geth/consolecmd.go | 18 | ||||
-rw-r--r-- | cmd/geth/consolecmd_test.go | 16 | ||||
-rw-r--r-- | cmd/geth/main.go | 22 | ||||
-rw-r--r-- | cmd/geth/monitorcmd.go | 5 | ||||
-rw-r--r-- | cmd/geth/run_test.go | 5 | ||||
-rw-r--r-- | cmd/geth/usage.go | 2 | ||||
-rw-r--r-- | cmd/utils/client.go | 2 | ||||
-rw-r--r-- | cmd/utils/customflags.go | 2 | ||||
-rw-r--r-- | cmd/utils/flags.go | 2 |
13 files changed, 79 insertions, 43 deletions
diff --git a/cmd/ethtest/main.go b/cmd/ethtest/main.go index d8f969636..e0ad0a7ea 100644 --- a/cmd/ethtest/main.go +++ b/cmd/ethtest/main.go @@ -25,10 +25,10 @@ import ( "path/filepath" "strings" - "github.com/codegangsta/cli" "github.com/ethereum/go-ethereum/logger/glog" "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/tests" + "gopkg.in/urfave/cli.v1" ) var ( @@ -183,7 +183,7 @@ func runSuite(test, file string) { } } -func setupApp(c *cli.Context) { +func setupApp(c *cli.Context) error { flagTest := c.GlobalString(TestFlag.Name) flagFile := c.GlobalString(FileFlag.Name) continueOnError = c.GlobalBool(ContinueOnErrorFlag.Name) @@ -196,8 +196,8 @@ func setupApp(c *cli.Context) { if err := runTestWithReader(flagTest, os.Stdin); err != nil { glog.Fatalln(err) } - } + return nil } func main() { diff --git a/cmd/evm/main.go b/cmd/evm/main.go index 7d9b3a6c3..e7b266d4e 100644 --- a/cmd/evm/main.go +++ b/cmd/evm/main.go @@ -24,7 +24,6 @@ import ( "runtime" "time" - "github.com/codegangsta/cli" "github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" @@ -33,6 +32,7 @@ import ( "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/logger/glog" + "gopkg.in/urfave/cli.v1" ) var ( @@ -104,7 +104,7 @@ func init() { app.Action = run } -func run(ctx *cli.Context) { +func run(ctx *cli.Context) error { glog.SetToStderr(true) glog.SetV(ctx.GlobalInt(VerbosityFlag.Name)) @@ -154,6 +154,7 @@ num gc: %d fmt.Printf(" error: %v", e) } fmt.Println() + return nil } func main() { diff --git a/cmd/geth/accountcmd.go b/cmd/geth/accountcmd.go index 0f9d95c2c..1415240eb 100644 --- a/cmd/geth/accountcmd.go +++ b/cmd/geth/accountcmd.go @@ -20,13 +20,13 @@ import ( "fmt" "io/ioutil" - "github.com/codegangsta/cli" "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/console" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger/glog" + "gopkg.in/urfave/cli.v1" ) var ( @@ -70,7 +70,7 @@ either new or import). Without it you are not able to unlock your account. Note that exporting your key in unencrypted format is NOT supported. -Keys are stored under <DATADIR>/keys. +Keys are stored under <DATADIR>/keystore. It is safe to transfer the entire directory or the individual keys therein between ethereum nodes by simply copying. Make sure you backup your keys regularly. @@ -167,11 +167,12 @@ nodes. } ) -func accountList(ctx *cli.Context) { +func accountList(ctx *cli.Context) error { accman := utils.MakeAccountManager(ctx) for i, acct := range accman.Accounts() { fmt.Printf("Account #%d: {%x} %s\n", i, acct.Address, acct.File) } + return nil } // tries unlocking the specified account a few times. @@ -259,7 +260,7 @@ func ambiguousAddrRecovery(am *accounts.Manager, err *accounts.AmbiguousAddrErro } // accountCreate creates a new account into the keystore defined by the CLI flags. -func accountCreate(ctx *cli.Context) { +func accountCreate(ctx *cli.Context) error { accman := utils.MakeAccountManager(ctx) password := getPassPhrase("Your new account is locked with a password. Please give a password. Do not forget this password.", true, 0, utils.MakePasswordList(ctx)) @@ -268,11 +269,12 @@ func accountCreate(ctx *cli.Context) { utils.Fatalf("Failed to create account: %v", err) } fmt.Printf("Address: {%x}\n", account.Address) + return nil } // accountUpdate transitions an account from a previous format to the current // one, also providing the possibility to change the pass-phrase. -func accountUpdate(ctx *cli.Context) { +func accountUpdate(ctx *cli.Context) error { if len(ctx.Args()) == 0 { utils.Fatalf("No accounts specified to update") } @@ -283,9 +285,10 @@ func accountUpdate(ctx *cli.Context) { if err := accman.Update(account, oldPassword, newPassword); err != nil { utils.Fatalf("Could not update the account: %v", err) } + return nil } -func importWallet(ctx *cli.Context) { +func importWallet(ctx *cli.Context) error { keyfile := ctx.Args().First() if len(keyfile) == 0 { utils.Fatalf("keyfile must be given as argument") @@ -303,9 +306,10 @@ func importWallet(ctx *cli.Context) { utils.Fatalf("%v", err) } fmt.Printf("Address: {%x}\n", acct.Address) + return nil } -func accountImport(ctx *cli.Context) { +func accountImport(ctx *cli.Context) error { keyfile := ctx.Args().First() if len(keyfile) == 0 { utils.Fatalf("keyfile must be given as argument") @@ -321,4 +325,5 @@ func accountImport(ctx *cli.Context) { utils.Fatalf("Could not create the account: %v", err) } fmt.Printf("Address: {%x}\n", acct.Address) + return nil } diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go index 274ad1809..321551ce0 100644 --- a/cmd/geth/chaincmd.go +++ b/cmd/geth/chaincmd.go @@ -23,7 +23,6 @@ import ( "strconv" "time" - "github.com/codegangsta/cli" "github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/console" @@ -32,6 +31,7 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/logger/glog" + "gopkg.in/urfave/cli.v1" ) var ( @@ -72,7 +72,7 @@ Use "ethereum dump 0" to dump the genesis block. } ) -func importChain(ctx *cli.Context) { +func importChain(ctx *cli.Context) error { if len(ctx.Args()) != 1 { utils.Fatalf("This command requires an argument.") } @@ -84,9 +84,10 @@ func importChain(ctx *cli.Context) { utils.Fatalf("Import error: %v", err) } fmt.Printf("Import done in %v", time.Since(start)) + return nil } -func exportChain(ctx *cli.Context) { +func exportChain(ctx *cli.Context) error { if len(ctx.Args()) < 1 { utils.Fatalf("This command requires an argument.") } @@ -114,9 +115,10 @@ func exportChain(ctx *cli.Context) { utils.Fatalf("Export error: %v\n", err) } fmt.Printf("Export done in %v", time.Since(start)) + return nil } -func removeDB(ctx *cli.Context) { +func removeDB(ctx *cli.Context) error { confirm, err := console.Stdin.PromptConfirm("Remove local database?") if err != nil { utils.Fatalf("%v", err) @@ -132,9 +134,10 @@ func removeDB(ctx *cli.Context) { } else { fmt.Println("Operation aborted") } + return nil } -func upgradeDB(ctx *cli.Context) { +func upgradeDB(ctx *cli.Context) error { glog.Infoln("Upgrading blockchain database") chain, chainDb := utils.MakeChain(ctx) @@ -163,9 +166,10 @@ func upgradeDB(ctx *cli.Context) { os.Remove(exportFile) glog.Infoln("Import finished") } + return nil } -func dump(ctx *cli.Context) { +func dump(ctx *cli.Context) error { chain, chainDb := utils.MakeChain(ctx) for _, arg := range ctx.Args() { var block *types.Block @@ -182,12 +186,12 @@ func dump(ctx *cli.Context) { state, err := state.New(block.Root(), chainDb) if err != nil { utils.Fatalf("could not create new state: %v", err) - return } fmt.Printf("%s\n", state.Dump()) } } chainDb.Close() + return nil } // hashish returns true for strings that look like hashes. diff --git a/cmd/geth/consolecmd.go b/cmd/geth/consolecmd.go index 8bfe27fef..257050a62 100644 --- a/cmd/geth/consolecmd.go +++ b/cmd/geth/consolecmd.go @@ -20,9 +20,9 @@ import ( "os" "os/signal" - "github.com/codegangsta/cli" "github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/console" + "gopkg.in/urfave/cli.v1" ) var ( @@ -60,7 +60,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso // localConsole starts a new geth node, attaching a JavaScript console to it at the // same time. -func localConsole(ctx *cli.Context) { +func localConsole(ctx *cli.Context) error { // Create and start the node based on the CLI flags node := utils.MakeSystemNode(clientIdentifier, verString, relConfig, makeDefaultExtra(), ctx) startNode(ctx, node) @@ -86,16 +86,18 @@ func localConsole(ctx *cli.Context) { // If only a short execution was requested, evaluate and return if script := ctx.GlobalString(utils.ExecFlag.Name); script != "" { console.Evaluate(script) - return + return nil } // Otherwise print the welcome screen and enter interactive mode console.Welcome() console.Interactive() + + return nil } // remoteConsole will connect to a remote geth instance, attaching a JavaScript // console to it. -func remoteConsole(ctx *cli.Context) { +func remoteConsole(ctx *cli.Context) error { // Attach to a remotely running geth instance and start the JavaScript console client, err := utils.NewRemoteRPCClient(ctx) if err != nil { @@ -116,17 +118,19 @@ func remoteConsole(ctx *cli.Context) { // If only a short execution was requested, evaluate and return if script := ctx.GlobalString(utils.ExecFlag.Name); script != "" { console.Evaluate(script) - return + return nil } // Otherwise print the welcome screen and enter interactive mode console.Welcome() console.Interactive() + + return nil } // ephemeralConsole starts a new geth node, attaches an ephemeral JavaScript // console to it, and each of the files specified as arguments and tears the // everything down. -func ephemeralConsole(ctx *cli.Context) { +func ephemeralConsole(ctx *cli.Context) error { // Create and start the node based on the CLI flags node := utils.MakeSystemNode(clientIdentifier, verString, relConfig, makeDefaultExtra(), ctx) startNode(ctx, node) @@ -164,4 +168,6 @@ func ephemeralConsole(ctx *cli.Context) { os.Exit(0) }() console.Stop(true) + + return nil } diff --git a/cmd/geth/consolecmd_test.go b/cmd/geth/consolecmd_test.go index e59fe1415..e0e549e12 100644 --- a/cmd/geth/consolecmd_test.go +++ b/cmd/geth/consolecmd_test.go @@ -17,7 +17,8 @@ package main import ( - "math/rand" + "crypto/rand" + "math/big" "os" "path/filepath" "runtime" @@ -73,7 +74,7 @@ func TestIPCAttachWelcome(t *testing.T) { coinbase := "0x8605cdbbdb6d264aa742e77020dcbc58fcdce182" var ipc string if runtime.GOOS == "windows" { - ipc = `\\.\pipe\geth` + strconv.Itoa(rand.Int()) + ipc = `\\.\pipe\geth` + strconv.Itoa(trulyRandInt(100000, 999999)) } else { ws := tmpdir(t) defer os.RemoveAll(ws) @@ -94,7 +95,7 @@ func TestIPCAttachWelcome(t *testing.T) { func TestHTTPAttachWelcome(t *testing.T) { coinbase := "0x8605cdbbdb6d264aa742e77020dcbc58fcdce182" - port := strconv.Itoa(rand.Intn(65535-1024) + 1024) // Yeah, sometimes this will fail, sorry :P + port := strconv.Itoa(trulyRandInt(1024, 65536)) // Yeah, sometimes this will fail, sorry :P geth := runGeth(t, "--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none", "--etherbase", coinbase, "--rpc", "--rpcport", port) @@ -108,7 +109,7 @@ func TestHTTPAttachWelcome(t *testing.T) { func TestWSAttachWelcome(t *testing.T) { coinbase := "0x8605cdbbdb6d264aa742e77020dcbc58fcdce182" - port := strconv.Itoa(rand.Intn(65535-1024) + 1024) // Yeah, sometimes this will fail, sorry :P + port := strconv.Itoa(trulyRandInt(1024, 65536)) // Yeah, sometimes this will fail, sorry :P geth := runGeth(t, "--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none", @@ -160,3 +161,10 @@ at block: 0 ({{niltime}}){{if ipc}} `) attach.expectExit() } + +// trulyRandInt generates a crypto random integer used by the console tests to +// not clash network ports with other tests running cocurrently. +func trulyRandInt(lo, hi int) int { + num, _ := rand.Int(rand.Reader, big.NewInt(int64(hi-lo))) + return int(num.Int64()) + lo +} diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 5ff1a7368..c372430f1 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -28,7 +28,6 @@ import ( "strings" "time" - "github.com/codegangsta/cli" "github.com/ethereum/ethash" "github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/common" @@ -44,6 +43,7 @@ import ( "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/release" "github.com/ethereum/go-ethereum/rlp" + "gopkg.in/urfave/cli.v1" ) const ( @@ -271,15 +271,17 @@ func makeDefaultExtra() []byte { // geth is the main entry point into the system if no special subcommand is ran. // It creates a default node based on the command line arguments and runs it in // blocking mode, waiting for it to be shut down. -func geth(ctx *cli.Context) { +func geth(ctx *cli.Context) error { node := utils.MakeSystemNode(clientIdentifier, verString, relConfig, makeDefaultExtra(), ctx) startNode(ctx, node) node.Wait() + + return nil } // initGenesis will initialise the given JSON format genesis file and writes it as // the zero'd block (i.e. genesis) or will fail hard if it can't succeed. -func initGenesis(ctx *cli.Context) { +func initGenesis(ctx *cli.Context) error { genesisPath := ctx.Args().First() if len(genesisPath) == 0 { utils.Fatalf("must supply path to genesis JSON file") @@ -300,6 +302,7 @@ func initGenesis(ctx *cli.Context) { utils.Fatalf("failed to write genesis block: %v", err) } glog.V(logger.Info).Infof("successfully wrote genesis block and/or chain rule set: %x", block.Hash()) + return nil } // startNode boots up the system node and all registered protocols, after which @@ -331,7 +334,7 @@ func startNode(ctx *cli.Context, stack *node.Node) { } } -func makedag(ctx *cli.Context) { +func makedag(ctx *cli.Context) error { args := ctx.Args() wrongArgs := func() { utils.Fatalf(`Usage: geth makedag <block number> <outputdir>`) @@ -358,13 +361,15 @@ func makedag(ctx *cli.Context) { default: wrongArgs() } + return nil } -func gpuinfo(ctx *cli.Context) { +func gpuinfo(ctx *cli.Context) error { eth.PrintOpenCLDevices() + return nil } -func gpubench(ctx *cli.Context) { +func gpubench(ctx *cli.Context) error { args := ctx.Args() wrongArgs := func() { utils.Fatalf(`Usage: geth gpubench <gpu number>`) @@ -381,9 +386,10 @@ func gpubench(ctx *cli.Context) { default: wrongArgs() } + return nil } -func version(c *cli.Context) { +func version(c *cli.Context) error { fmt.Println(clientIdentifier) fmt.Println("Version:", verString) fmt.Println("Protocol Versions:", eth.ProtocolVersions) @@ -392,4 +398,6 @@ func version(c *cli.Context) { fmt.Println("OS:", runtime.GOOS) fmt.Printf("GOPATH=%s\n", os.Getenv("GOPATH")) fmt.Printf("GOROOT=%s\n", runtime.GOROOT()) + + return nil } diff --git a/cmd/geth/monitorcmd.go b/cmd/geth/monitorcmd.go index 5d839b5a3..11fdca89c 100644 --- a/cmd/geth/monitorcmd.go +++ b/cmd/geth/monitorcmd.go @@ -26,11 +26,11 @@ import ( "sort" - "github.com/codegangsta/cli" "github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/rpc" "github.com/gizak/termui" + "gopkg.in/urfave/cli.v1" ) var ( @@ -67,7 +67,7 @@ to display multiple metrics simultaneously. ) // monitor starts a terminal UI based monitoring tool for the requested metrics. -func monitor(ctx *cli.Context) { +func monitor(ctx *cli.Context) error { var ( client rpc.Client err error @@ -154,6 +154,7 @@ func monitor(ctx *cli.Context) { } }() termui.Loop() + return nil } // retrieveMetrics contacts the attached geth node and retrieves the entire set diff --git a/cmd/geth/run_test.go b/cmd/geth/run_test.go index f6bc3f869..e26b4509a 100644 --- a/cmd/geth/run_test.go +++ b/cmd/geth/run_test.go @@ -58,7 +58,10 @@ type testgeth struct { func init() { // Run the app if we're the child process for runGeth. if os.Getenv("GETH_TEST_CHILD") != "" { - app.RunAndExitOnError() + if err := app.Run(os.Args); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } os.Exit(0) } } diff --git a/cmd/geth/usage.go b/cmd/geth/usage.go index 01a71c1f6..e7ef9e2c7 100644 --- a/cmd/geth/usage.go +++ b/cmd/geth/usage.go @@ -21,9 +21,9 @@ package main import ( "io" - "github.com/codegangsta/cli" "github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/internal/debug" + "gopkg.in/urfave/cli.v1" ) // AppHelpTemplate is the test template for the default, global app help topic. diff --git a/cmd/utils/client.go b/cmd/utils/client.go index ec72a1a4b..cc9647580 100644 --- a/cmd/utils/client.go +++ b/cmd/utils/client.go @@ -20,9 +20,9 @@ import ( "fmt" "strings" - "github.com/codegangsta/cli" "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/rpc" + "gopkg.in/urfave/cli.v1" ) // NewRemoteRPCClient returns a RPC client which connects to a running geth instance. diff --git a/cmd/utils/customflags.go b/cmd/utils/customflags.go index 4450065c1..5cbccfe98 100644 --- a/cmd/utils/customflags.go +++ b/cmd/utils/customflags.go @@ -24,7 +24,7 @@ import ( "path" "strings" - "github.com/codegangsta/cli" + "gopkg.in/urfave/cli.v1" ) // Custom type which is registered in the flags library which cli uses for diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 6547aae42..14898b987 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -30,7 +30,6 @@ import ( "strings" "time" - "github.com/codegangsta/cli" "github.com/ethereum/ethash" "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/common" @@ -51,6 +50,7 @@ import ( "github.com/ethereum/go-ethereum/release" "github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/whisper" + "gopkg.in/urfave/cli.v1" ) func init() { |