diff options
-rw-r--r-- | cmd/geth/main.go | 2 | ||||
-rw-r--r-- | cmd/swarm/main.go | 2 | ||||
-rw-r--r-- | core/vm/runtime/env.go | 3 | ||||
-rw-r--r-- | core/vm/runtime/runtime.go | 6 | ||||
-rw-r--r-- | ethdb/database_test.go | 15 | ||||
-rw-r--r-- | ethdb/memory_database.go | 2 | ||||
-rw-r--r-- | tests/block_test.go | 55 | ||||
-rw-r--r-- | tests/block_test_util.go | 8 | ||||
-rw-r--r-- | tests/init.go | 88 | ||||
-rw-r--r-- | tests/state_test.go | 8 | ||||
-rw-r--r-- | tests/state_test_util.go | 35 | ||||
m--------- | tests/testdata | 0 | ||||
-rw-r--r-- | vendor/gopkg.in/urfave/cli.v1/CHANGELOG.md | 43 | ||||
-rw-r--r-- | vendor/gopkg.in/urfave/cli.v1/README.md | 33 | ||||
-rw-r--r-- | vendor/gopkg.in/urfave/cli.v1/app.go | 7 | ||||
-rw-r--r-- | vendor/gopkg.in/urfave/cli.v1/appveyor.yml | 10 | ||||
-rw-r--r-- | vendor/gopkg.in/urfave/cli.v1/cli.go | 1 | ||||
-rw-r--r-- | vendor/gopkg.in/urfave/cli.v1/command.go | 44 | ||||
-rw-r--r-- | vendor/gopkg.in/urfave/cli.v1/context.go | 2 | ||||
-rw-r--r-- | vendor/gopkg.in/urfave/cli.v1/errors.go | 23 | ||||
-rw-r--r-- | vendor/gopkg.in/urfave/cli.v1/flag.go | 12 | ||||
-rw-r--r-- | vendor/gopkg.in/urfave/cli.v1/help.go | 68 | ||||
-rw-r--r-- | vendor/vendor.json | 6 |
23 files changed, 327 insertions, 146 deletions
diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 34d1d8406..8166c9ce8 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -21,6 +21,7 @@ import ( "fmt" "os" "runtime" + "sort" "strings" "time" @@ -165,6 +166,7 @@ func init() { // See config.go dumpConfigCommand, } + sort.Sort(cli.CommandsByName(app.Commands)) app.Flags = append(app.Flags, nodeFlags...) app.Flags = append(app.Flags, rpcFlags...) diff --git a/cmd/swarm/main.go b/cmd/swarm/main.go index 449d11f36..603fd9b94 100644 --- a/cmd/swarm/main.go +++ b/cmd/swarm/main.go @@ -25,6 +25,7 @@ import ( "os" "os/signal" "runtime" + "sort" "strconv" "strings" "syscall" @@ -302,6 +303,7 @@ DEPRECATED: use 'swarm db clean'. `, }, } + sort.Sort(cli.CommandsByName(app.Commands)) app.Flags = []cli.Flag{ utils.IdentityFlag, diff --git a/core/vm/runtime/env.go b/core/vm/runtime/env.go index 7b41fe85a..818da1be2 100644 --- a/core/vm/runtime/env.go +++ b/core/vm/runtime/env.go @@ -21,11 +21,10 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" - "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/vm" ) -func NewEnv(cfg *Config, state *state.StateDB) *vm.EVM { +func NewEnv(cfg *Config) *vm.EVM { context := vm.Context{ CanTransfer: core.CanTransfer, Transfer: core.Transfer, diff --git a/core/vm/runtime/runtime.go b/core/vm/runtime/runtime.go index 44cde4f70..edbf54176 100644 --- a/core/vm/runtime/runtime.go +++ b/core/vm/runtime/runtime.go @@ -106,7 +106,7 @@ func Execute(code, input []byte, cfg *Config) ([]byte, *state.StateDB, error) { } var ( address = common.StringToAddress("contract") - vmenv = NewEnv(cfg, cfg.State) + vmenv = NewEnv(cfg) sender = vm.AccountRef(cfg.Origin) ) cfg.State.CreateAccount(address) @@ -136,7 +136,7 @@ func Create(input []byte, cfg *Config) ([]byte, common.Address, uint64, error) { cfg.State, _ = state.New(common.Hash{}, state.NewDatabase(db)) } var ( - vmenv = NewEnv(cfg, cfg.State) + vmenv = NewEnv(cfg) sender = vm.AccountRef(cfg.Origin) ) @@ -158,7 +158,7 @@ func Create(input []byte, cfg *Config) ([]byte, common.Address, uint64, error) { func Call(address common.Address, input []byte, cfg *Config) ([]byte, uint64, error) { setDefaults(cfg) - vmenv := NewEnv(cfg, cfg.State) + vmenv := NewEnv(cfg) sender := cfg.State.GetOrNewStateObject(cfg.Origin) // Call the code with the given configuration. diff --git a/ethdb/database_test.go b/ethdb/database_test.go index 4740cdaed..5e4a3ca34 100644 --- a/ethdb/database_test.go +++ b/ethdb/database_test.go @@ -95,6 +95,21 @@ func testPutGet(db ethdb.Database, t *testing.T) { } for _, v := range test_values { + orig, err := db.Get([]byte(v)) + if err != nil { + t.Fatalf("get failed: %v", err) + } + orig[0] = byte(0xff) + data, err := db.Get([]byte(v)) + if err != nil { + t.Fatalf("get failed: %v", err) + } + if !bytes.Equal(data, []byte("?")) { + t.Fatalf("get returned wrong result, got %q expected ?", string(data)) + } + } + + for _, v := range test_values { err := db.Delete([]byte(v)) if err != nil { t.Fatalf("delete %q failed: %v", v, err) diff --git a/ethdb/memory_database.go b/ethdb/memory_database.go index a2ee2f2cc..11b093724 100644 --- a/ethdb/memory_database.go +++ b/ethdb/memory_database.go @@ -50,7 +50,7 @@ func (db *MemDatabase) Get(key []byte) ([]byte, error) { defer db.lock.RUnlock() if entry, ok := db.db[string(key)]; ok { - return entry, nil + return common.CopyBytes(entry), nil } return nil, errors.New("not found") } diff --git a/tests/block_test.go b/tests/block_test.go index 3245aca7d..6fc66b17c 100644 --- a/tests/block_test.go +++ b/tests/block_test.go @@ -17,10 +17,7 @@ package tests import ( - "math/big" "testing" - - "github.com/ethereum/go-ethereum/params" ) func TestBlockchain(t *testing.T) { @@ -30,51 +27,19 @@ func TestBlockchain(t *testing.T) { // General state tests are 'exported' as blockchain tests, but we can run them natively. bt.skipLoad(`^GeneralStateTests/`) // Skip random failures due to selfish mining test. - bt.skipLoad(`bcForkUncle\.json/ForkUncle`) - bt.skipLoad(`^bcMultiChainTest\.json/ChainAtoChainB_blockorder`) - bt.skipLoad(`^bcTotalDifficultyTest\.json/(lotsOfLeafs|lotsOfBranches|sideChainWithMoreTransactions)$`) - bt.skipLoad(`^bcMultiChainTest\.json/CallContractFromNotBestBlock`) + bt.skipLoad(`^bcForgedTest/bcForkUncle\.json`) + bt.skipLoad(`^bcMultiChainTest/(ChainAtoChainB_blockorder|CallContractFromNotBestBlock)`) + bt.skipLoad(`^bcTotalDifficultyTest/(lotsOfLeafs|lotsOfBranches|sideChainWithMoreTransactions)`) + // Constantinople is not implemented yet. + bt.skipLoad(`(?i)(constantinople)`) // Expected failures: - bt.fails(`(?i)metropolis`, "metropolis is not supported yet") - bt.fails(`^TestNetwork/bcTheDaoTest\.json/(DaoTransactions$|DaoTransactions_UncleExtradata$)`, "issue in test") - - bt.config(`^TestNetwork/`, params.ChainConfig{ - HomesteadBlock: big.NewInt(5), - DAOForkBlock: big.NewInt(8), - DAOForkSupport: true, - EIP150Block: big.NewInt(10), - EIP155Block: big.NewInt(10), - EIP158Block: big.NewInt(14), - // MetropolisBlock: big.NewInt(16), - }) - bt.config(`^RandomTests/.*EIP150`, params.ChainConfig{ - HomesteadBlock: big.NewInt(0), - EIP150Block: big.NewInt(0), - }) - bt.config(`^RandomTests/.*EIP158`, params.ChainConfig{ - HomesteadBlock: big.NewInt(0), - EIP150Block: big.NewInt(0), - EIP155Block: big.NewInt(0), - EIP158Block: big.NewInt(0), - }) - bt.config(`^RandomTests/`, params.ChainConfig{ - HomesteadBlock: big.NewInt(0), - EIP150Block: big.NewInt(10), - }) - bt.config(`^Homestead/`, params.ChainConfig{ - HomesteadBlock: big.NewInt(0), - }) - bt.config(`^EIP150/`, params.ChainConfig{ - HomesteadBlock: big.NewInt(0), - EIP150Block: big.NewInt(0), - }) - bt.config(`^[^/]+\.json`, params.ChainConfig{ - HomesteadBlock: big.NewInt(1000000), - }) + bt.fails("^TransitionTests/bcEIP158ToByzantium", "byzantium not supported") + bt.fails(`^TransitionTests/bcHomesteadToDao/DaoTransactions(|_UncleExtradata|_EmptyTransactionAndForkBlocksAhead)\.json`, "issue in test") + bt.fails(`^bc(Exploit|Fork|Gas|Multi|Total|State|Random|Uncle|Valid|Wallet).*_Byzantium$`, "byzantium not supported") + bt.fails(`^bcBlockGasLimitTest/(BlockGasLimit2p63m1|TransactionGasHigherThanLimit2p63m1|SuicideTransaction|GasUsedHigherThanBlockGasLimitButNotWithRefundsSuicideFirst|TransactionGasHigherThanLimit2p63m1_2).*_Byzantium$`, "byzantium not supported") bt.walk(t, blockTestDir, func(t *testing.T, name string, test *BlockTest) { - cfg := bt.findConfig(name) - if err := bt.checkFailure(t, name, test.Run(cfg)); err != nil { + if err := bt.checkFailure(t, name, test.Run()); err != nil { t.Error(err) } }) diff --git a/tests/block_test_util.go b/tests/block_test_util.go index a74f7d68d..c1d433ff3 100644 --- a/tests/block_test_util.go +++ b/tests/block_test_util.go @@ -53,6 +53,7 @@ type btJSON struct { Pre core.GenesisAlloc `json:"pre"` Post core.GenesisAlloc `json:"postState"` BestBlock common.UnprefixedHash `json:"lastblockhash"` + Network string `json:"network"` } type btBlock struct { @@ -91,7 +92,12 @@ type btHeaderMarshaling struct { Timestamp *math.HexOrDecimal256 } -func (t *BlockTest) Run(config *params.ChainConfig) error { +func (t *BlockTest) Run() error { + config, ok := Forks[t.json.Network] + if !ok { + return UnsupportedForkError{t.json.Network} + } + // import pre accounts & construct test genesis block & state root db, _ := ethdb.NewMemDatabase() gblock, err := t.genesis(config).Commit(db) diff --git a/tests/init.go b/tests/init.go new file mode 100644 index 000000000..0c3fe61d1 --- /dev/null +++ b/tests/init.go @@ -0,0 +1,88 @@ +// Copyright 2017 The go-ethereum Authors +// This file is part of the go-ethereum library. +// +// The go-ethereum library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The go-ethereum library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. + +package tests + +import ( + "fmt" + "math/big" + + "github.com/ethereum/go-ethereum/params" +) + +// This table defines supported forks and their chain config. +var Forks = map[string]*params.ChainConfig{ + "Frontier": ¶ms.ChainConfig{ + ChainId: big.NewInt(1), + }, + "Homestead": ¶ms.ChainConfig{ + ChainId: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + }, + "EIP150": ¶ms.ChainConfig{ + ChainId: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + EIP150Block: big.NewInt(0), + }, + "EIP158": ¶ms.ChainConfig{ + ChainId: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + EIP150Block: big.NewInt(0), + EIP155Block: big.NewInt(0), + EIP158Block: big.NewInt(0), + }, + "Byzantium": ¶ms.ChainConfig{ + ChainId: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + EIP150Block: big.NewInt(0), + EIP155Block: big.NewInt(0), + EIP158Block: big.NewInt(0), + DAOForkBlock: big.NewInt(0), + MetropolisBlock: big.NewInt(0), + }, + "FrontierToHomesteadAt5": ¶ms.ChainConfig{ + ChainId: big.NewInt(1), + HomesteadBlock: big.NewInt(5), + }, + "HomesteadToEIP150At5": ¶ms.ChainConfig{ + ChainId: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + EIP150Block: big.NewInt(5), + }, + "HomesteadToDaoAt5": ¶ms.ChainConfig{ + ChainId: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + DAOForkBlock: big.NewInt(5), + DAOForkSupport: true, + }, + "EIP158ToByzantiumAt5": ¶ms.ChainConfig{ + ChainId: big.NewInt(1), + HomesteadBlock: big.NewInt(0), + EIP150Block: big.NewInt(0), + EIP155Block: big.NewInt(0), + EIP158Block: big.NewInt(0), + MetropolisBlock: big.NewInt(5), + }, +} + +// UnsupportedForkError is returned when a test requests a fork that isn't implemented. +type UnsupportedForkError struct { + Name string +} + +func (e UnsupportedForkError) Error() string { + return fmt.Sprintf("unsupported fork %q", e.Name) +} diff --git a/tests/state_test.go b/tests/state_test.go index e4e691589..ab6dc423f 100644 --- a/tests/state_test.go +++ b/tests/state_test.go @@ -33,11 +33,9 @@ func TestState(t *testing.T) { st.skipShortMode(`^stQuadraticComplexityTest/`) // Broken tests: st.skipLoad(`^stTransactionTest/OverflowGasRequire\.json`) // gasLimit > 256 bits - st.skipLoad(`^stStackTests/shallowStackOK\.json`) // bad hex encoding st.skipLoad(`^stTransactionTest/zeroSigTransa[^/]*\.json`) // EIP-86 is not supported yet // Expected failures: - st.fails(`^stCallCreateCallCodeTest/createJS_ExampleContract\.json`, "bug in test") - st.fails(`^stCodeSizeLimit/codesizeOOGInvalidSize\.json/(Frontier|Homestead)`, + st.fails(`^stCodeSizeLimit/codesizeOOGInvalidSize\.json/(Frontier|Homestead|EIP150)`, "code size limit implementation is not conditional on fork") st.fails(`^stRevertTest/RevertDepthCreateAddressCollision\.json/EIP15[08]/[67]`, "bug in test") st.fails(`^stRevertTest/RevertPrecompiledTouch\.json/EIP158`, "bug in test") @@ -49,8 +47,8 @@ func TestState(t *testing.T) { key := fmt.Sprintf("%s/%d", subtest.Fork, subtest.Index) name := name + "/" + key t.Run(key, func(t *testing.T) { - if subtest.Fork == "Metropolis" { - t.Skip("metropolis not supported yet") + if subtest.Fork == "Constantinople" || subtest.Fork == "Byzantium" { + t.Skip("constantinople, byzantium not supported yet") } withTrace(t, test.gasLimit(subtest), func(vmconfig vm.Config) error { return st.checkFailure(t, name, test.Run(subtest, vmconfig)) diff --git a/tests/state_test_util.go b/tests/state_test_util.go index 5c7ed5d67..2bf940bab 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -37,37 +37,6 @@ import ( "github.com/ethereum/go-ethereum/params" ) -// This table defines supported forks and their chain config. -var stateTestForks = map[string]*params.ChainConfig{ - "Frontier": ¶ms.ChainConfig{ - ChainId: big.NewInt(1), - }, - "Homestead": ¶ms.ChainConfig{ - HomesteadBlock: big.NewInt(0), - ChainId: big.NewInt(1), - }, - "EIP150": ¶ms.ChainConfig{ - HomesteadBlock: big.NewInt(0), - EIP150Block: big.NewInt(0), - ChainId: big.NewInt(1), - }, - "EIP158": ¶ms.ChainConfig{ - HomesteadBlock: big.NewInt(0), - EIP150Block: big.NewInt(0), - EIP155Block: big.NewInt(0), - EIP158Block: big.NewInt(0), - ChainId: big.NewInt(1), - }, - "Metropolis": ¶ms.ChainConfig{ - HomesteadBlock: big.NewInt(0), - EIP150Block: big.NewInt(0), - EIP155Block: big.NewInt(0), - EIP158Block: big.NewInt(0), - MetropolisBlock: big.NewInt(0), - ChainId: big.NewInt(1), - }, -} - // StateTest checks transaction processing without block context. // See https://github.com/ethereum/EIPs/issues/176 for the test format specification. type StateTest struct { @@ -167,9 +136,9 @@ func (t *StateTest) Subtests() []StateSubtest { // Run executes a specific subtest. func (t *StateTest) Run(subtest StateSubtest, vmconfig vm.Config) error { - config, ok := stateTestForks[subtest.Fork] + config, ok := Forks[subtest.Fork] if !ok { - return fmt.Errorf("no config for fork %q", subtest.Fork) + return UnsupportedForkError{subtest.Fork} } block, _ := t.genesis(config).ToBlock() db, _ := ethdb.NewMemDatabase() diff --git a/tests/testdata b/tests/testdata -Subproject f1de8c3b7fa2c2c0aa281b6b3a1ad7010356c5f +Subproject 815151e4cea4e73328f8586b4e61c3d7e1e9e54 diff --git a/vendor/gopkg.in/urfave/cli.v1/CHANGELOG.md b/vendor/gopkg.in/urfave/cli.v1/CHANGELOG.md index 07f75464b..401eae5a2 100644 --- a/vendor/gopkg.in/urfave/cli.v1/CHANGELOG.md +++ b/vendor/gopkg.in/urfave/cli.v1/CHANGELOG.md @@ -4,6 +4,49 @@ ## [Unreleased] +## 1.20.0 - 2017-08-10 + +### Fixed + +* `HandleExitCoder` is now correctly iterates over all errors in + a `MultiError`. The exit code is the exit code of the last error or `1` if + there are no `ExitCoder`s in the `MultiError`. +* Fixed YAML file loading on Windows (previously would fail validate the file path) +* Subcommand `Usage`, `Description`, `ArgsUsage`, `OnUsageError` correctly + propogated +* `ErrWriter` is now passed downwards through command structure to avoid the + need to redefine it +* Pass `Command` context into `OnUsageError` rather than parent context so that + all fields are avaiable +* Errors occuring in `Before` funcs are no longer double printed +* Use `UsageText` in the help templates for commands and subcommands if + defined; otherwise build the usage as before (was previously ignoring this + field) +* `IsSet` and `GlobalIsSet` now correctly return whether a flag is set if + a program calls `Set` or `GlobalSet` directly after flag parsing (would + previously only return `true` if the flag was set during parsing) + +### Changed + +* No longer exit the program on command/subcommand error if the error raised is + not an `OsExiter`. This exiting behavior was introduced in 1.19.0, but was + determined to be a regression in functionality. See [the + PR](https://github.com/urfave/cli/pull/595) for discussion. + +### Added + +* `CommandsByName` type was added to make it easy to sort `Command`s by name, + alphabetically +* `altsrc` now handles loading of string and int arrays from TOML +* Support for definition of custom help templates for `App` via + `CustomAppHelpTemplate` +* Support for arbitrary key/value fields on `App` to be used with + `CustomAppHelpTemplate` via `ExtraInfo` +* `HelpFlag`, `VersionFlag`, and `BashCompletionFlag` changed to explictly be + `cli.Flag`s allowing for the use of custom flags satisfying the `cli.Flag` + interface to be used. + + ## [1.19.1] - 2016-11-21 ### Fixed diff --git a/vendor/gopkg.in/urfave/cli.v1/README.md b/vendor/gopkg.in/urfave/cli.v1/README.md index bb5f61eaf..2bbbd8ea9 100644 --- a/vendor/gopkg.in/urfave/cli.v1/README.md +++ b/vendor/gopkg.in/urfave/cli.v1/README.md @@ -455,13 +455,13 @@ error. Flags for the application and commands are shown in the order they are defined. However, it's possible to sort them from outside this library by using `FlagsByName` -with `sort`. +or `CommandsByName` with `sort`. For example this: <!-- { "args": ["--help"], - "output": "Load configuration from FILE\n.*Language for the greeting.*" + "output": "add a task to the list\n.*complete a task on the list\n.*\n\n.*\n.*Load configuration from FILE\n.*Language for the greeting.*" } --> ``` go package main @@ -488,7 +488,27 @@ func main() { }, } + app.Commands = []cli.Command{ + { + Name: "complete", + Aliases: []string{"c"}, + Usage: "complete a task on the list", + Action: func(c *cli.Context) error { + return nil + }, + }, + { + Name: "add", + Aliases: []string{"a"}, + Usage: "add a task to the list", + Action: func(c *cli.Context) error { + return nil + }, + }, + } + sort.Sort(cli.FlagsByName(app.Flags)) + sort.Sort(cli.CommandsByName(app.Commands)) app.Run(os.Args) } @@ -940,16 +960,13 @@ SUPPORT: support@awesometown.example.com cli.AppHelpTemplate = `NAME: {{.Name}} - {{.Usage}} USAGE: - {{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}{{if .Commands}} command -[command options]{{end}} {{if -.ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}} + {{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}} {{if len .Authors}} -AUTHOR(S): +AUTHOR: {{range .Authors}}{{ . }}{{end}} {{end}}{{if .Commands}} COMMANDS: -{{range .Commands}}{{if not .HideHelp}} {{join .Names ", "}}{{ "\t" -}}{{.Usage}}{{ "\n" }}{{end}}{{end}}{{end}}{{if .VisibleFlags}} +{{range .Commands}}{{if not .HideHelp}} {{join .Names ", "}}{{ "\t"}}{{.Usage}}{{ "\n" }}{{end}}{{end}}{{end}}{{if .VisibleFlags}} GLOBAL OPTIONS: {{range .VisibleFlags}}{{.}} {{end}}{{end}}{{if .Copyright }} diff --git a/vendor/gopkg.in/urfave/cli.v1/app.go b/vendor/gopkg.in/urfave/cli.v1/app.go index 95ffc0b97..51fc45d87 100644 --- a/vendor/gopkg.in/urfave/cli.v1/app.go +++ b/vendor/gopkg.in/urfave/cli.v1/app.go @@ -85,6 +85,12 @@ type App struct { ErrWriter io.Writer // Other custom info Metadata map[string]interface{} + // Carries a function which returns app specific info. + ExtraInfo func() map[string]string + // CustomAppHelpTemplate the text template for app help topic. + // cli.go uses text/template to render templates. You can + // render custom help text by setting this variable. + CustomAppHelpTemplate string didSetup bool } @@ -234,7 +240,6 @@ func (a *App) Run(arguments []string) (err error) { if a.Before != nil { beforeErr := a.Before(context) if beforeErr != nil { - fmt.Fprintf(a.Writer, "%v\n\n", beforeErr) ShowAppHelp(context) HandleExitCoder(beforeErr) err = beforeErr diff --git a/vendor/gopkg.in/urfave/cli.v1/appveyor.yml b/vendor/gopkg.in/urfave/cli.v1/appveyor.yml index 698b188e1..1e1489c36 100644 --- a/vendor/gopkg.in/urfave/cli.v1/appveyor.yml +++ b/vendor/gopkg.in/urfave/cli.v1/appveyor.yml @@ -1,14 +1,16 @@ version: "{build}" -os: Windows Server 2012 R2 +os: Windows Server 2016 + +image: Visual Studio 2017 clone_folder: c:\gopath\src\github.com\urfave\cli environment: GOPATH: C:\gopath - GOVERSION: 1.6 - PYTHON: C:\Python27-x64 - PYTHON_VERSION: 2.7.x + GOVERSION: 1.8.x + PYTHON: C:\Python36-x64 + PYTHON_VERSION: 3.6.x PYTHON_ARCH: 64 install: diff --git a/vendor/gopkg.in/urfave/cli.v1/cli.go b/vendor/gopkg.in/urfave/cli.v1/cli.go index 74fd101f4..90c07eb8e 100644 --- a/vendor/gopkg.in/urfave/cli.v1/cli.go +++ b/vendor/gopkg.in/urfave/cli.v1/cli.go @@ -12,6 +12,7 @@ // app.Usage = "say a greeting" // app.Action = func(c *cli.Context) error { // println("Greetings") +// return nil // } // // app.Run(os.Args) diff --git a/vendor/gopkg.in/urfave/cli.v1/command.go b/vendor/gopkg.in/urfave/cli.v1/command.go index 2628fbf48..23de2944b 100644 --- a/vendor/gopkg.in/urfave/cli.v1/command.go +++ b/vendor/gopkg.in/urfave/cli.v1/command.go @@ -59,6 +59,25 @@ type Command struct { // Full name of command for help, defaults to full command name, including parent commands. HelpName string commandNamePath []string + + // CustomHelpTemplate the text template for the command help topic. + // cli.go uses text/template to render templates. You can + // render custom help text by setting this variable. + CustomHelpTemplate string +} + +type CommandsByName []Command + +func (c CommandsByName) Len() int { + return len(c) +} + +func (c CommandsByName) Less(i, j int) bool { + return c[i].Name < c[j].Name +} + +func (c CommandsByName) Swap(i, j int) { + c[i], c[j] = c[j], c[i] } // FullName returns the full name of the command. @@ -140,19 +159,20 @@ func (c Command) Run(ctx *Context) (err error) { } context := NewContext(ctx.App, set, ctx) + context.Command = c if checkCommandCompletions(context, c.Name) { return nil } if err != nil { if c.OnUsageError != nil { - err := c.OnUsageError(ctx, err, false) + err := c.OnUsageError(context, err, false) HandleExitCoder(err) return err } - fmt.Fprintln(ctx.App.Writer, "Incorrect Usage:", err.Error()) - fmt.Fprintln(ctx.App.Writer) - ShowCommandHelp(ctx, c.Name) + fmt.Fprintln(context.App.Writer, "Incorrect Usage:", err.Error()) + fmt.Fprintln(context.App.Writer) + ShowCommandHelp(context, c.Name) return err } @@ -177,9 +197,7 @@ func (c Command) Run(ctx *Context) (err error) { if c.Before != nil { err = c.Before(context) if err != nil { - fmt.Fprintln(ctx.App.Writer, err) - fmt.Fprintln(ctx.App.Writer) - ShowCommandHelp(ctx, c.Name) + ShowCommandHelp(context, c.Name) HandleExitCoder(err) return err } @@ -189,7 +207,6 @@ func (c Command) Run(ctx *Context) (err error) { c.Action = helpSubcommand.Action } - context.Command = c err = HandleAction(c.Action, context) if err != nil { @@ -230,14 +247,13 @@ func (c Command) startApp(ctx *Context) error { app.HelpName = app.Name } - if c.Description != "" { - app.Usage = c.Description - } else { - app.Usage = c.Usage - } + app.Usage = c.Usage + app.Description = c.Description + app.ArgsUsage = c.ArgsUsage // set CommandNotFound app.CommandNotFound = ctx.App.CommandNotFound + app.CustomAppHelpTemplate = c.CustomHelpTemplate // set the flags and commands app.Commands = c.Subcommands @@ -250,6 +266,7 @@ func (c Command) startApp(ctx *Context) error { app.Author = ctx.App.Author app.Email = ctx.App.Email app.Writer = ctx.App.Writer + app.ErrWriter = ctx.App.ErrWriter app.categories = CommandCategories{} for _, command := range c.Subcommands { @@ -272,6 +289,7 @@ func (c Command) startApp(ctx *Context) error { } else { app.Action = helpSubcommand.Action } + app.OnUsageError = c.OnUsageError for index, cc := range app.Commands { app.Commands[index].commandNamePath = []string{c.Name, cc.Name} diff --git a/vendor/gopkg.in/urfave/cli.v1/context.go b/vendor/gopkg.in/urfave/cli.v1/context.go index cb89e92a0..db94191e2 100644 --- a/vendor/gopkg.in/urfave/cli.v1/context.go +++ b/vendor/gopkg.in/urfave/cli.v1/context.go @@ -39,11 +39,13 @@ func (c *Context) NumFlags() int { // Set sets a context flag to a value. func (c *Context) Set(name, value string) error { + c.setFlags = nil return c.flagSet.Set(name, value) } // GlobalSet sets a context flag to a value on the global flagset func (c *Context) GlobalSet(name, value string) error { + globalContext(c).setFlags = nil return globalContext(c).flagSet.Set(name, value) } diff --git a/vendor/gopkg.in/urfave/cli.v1/errors.go b/vendor/gopkg.in/urfave/cli.v1/errors.go index 0206ff491..562b2953c 100644 --- a/vendor/gopkg.in/urfave/cli.v1/errors.go +++ b/vendor/gopkg.in/urfave/cli.v1/errors.go @@ -74,7 +74,7 @@ func (ee *ExitError) ExitCode() int { // HandleExitCoder checks if the error fulfills the ExitCoder interface, and if // so prints the error to stderr (if it is non-empty) and calls OsExiter with the // given exit code. If the given error is a MultiError, then this func is -// called on all members of the Errors slice. +// called on all members of the Errors slice and calls OsExiter with the last exit code. func HandleExitCoder(err error) { if err == nil { return @@ -93,18 +93,23 @@ func HandleExitCoder(err error) { } if multiErr, ok := err.(MultiError); ok { - for _, merr := range multiErr.Errors { - HandleExitCoder(merr) - } + code := handleMultiError(multiErr) + OsExiter(code) return } +} - if err.Error() != "" { - if _, ok := err.(ErrorFormatter); ok { - fmt.Fprintf(ErrWriter, "%+v\n", err) +func handleMultiError(multiErr MultiError) int { + code := 1 + for _, merr := range multiErr.Errors { + if multiErr2, ok := merr.(MultiError); ok { + code = handleMultiError(multiErr2) } else { - fmt.Fprintln(ErrWriter, err) + fmt.Fprintln(ErrWriter, merr) + if exitErr, ok := merr.(ExitCoder); ok { + code = exitErr.ExitCode() + } } } - OsExiter(1) + return code } diff --git a/vendor/gopkg.in/urfave/cli.v1/flag.go b/vendor/gopkg.in/urfave/cli.v1/flag.go index 7dd8a2c4a..877ff3523 100644 --- a/vendor/gopkg.in/urfave/cli.v1/flag.go +++ b/vendor/gopkg.in/urfave/cli.v1/flag.go @@ -14,13 +14,13 @@ import ( const defaultPlaceholder = "value" // BashCompletionFlag enables bash-completion for all commands and subcommands -var BashCompletionFlag = BoolFlag{ +var BashCompletionFlag Flag = BoolFlag{ Name: "generate-bash-completion", Hidden: true, } // VersionFlag prints the version for the application -var VersionFlag = BoolFlag{ +var VersionFlag Flag = BoolFlag{ Name: "version, v", Usage: "print the version", } @@ -28,7 +28,7 @@ var VersionFlag = BoolFlag{ // HelpFlag prints the help for all commands and subcommands // Set to the zero value (BoolFlag{}) to disable flag -- keeps subcommand // unless HideHelp is set to true) -var HelpFlag = BoolFlag{ +var HelpFlag Flag = BoolFlag{ Name: "help, h", Usage: "show help", } @@ -630,7 +630,8 @@ func (f Float64Flag) ApplyWithError(set *flag.FlagSet) error { func visibleFlags(fl []Flag) []Flag { visible := []Flag{} for _, flag := range fl { - if !flagValue(flag).FieldByName("Hidden").Bool() { + field := flagValue(flag).FieldByName("Hidden") + if !field.IsValid() || !field.Bool() { visible = append(visible, flag) } } @@ -723,9 +724,8 @@ func stringifyFlag(f Flag) string { needsPlaceholder := false defaultValueString := "" - val := fv.FieldByName("Value") - if val.IsValid() { + if val := fv.FieldByName("Value"); val.IsValid() { needsPlaceholder = true defaultValueString = fmt.Sprintf(" (default: %v)", val.Interface()) diff --git a/vendor/gopkg.in/urfave/cli.v1/help.go b/vendor/gopkg.in/urfave/cli.v1/help.go index c8c1aee05..57ec98d58 100644 --- a/vendor/gopkg.in/urfave/cli.v1/help.go +++ b/vendor/gopkg.in/urfave/cli.v1/help.go @@ -47,7 +47,7 @@ var CommandHelpTemplate = `NAME: {{.HelpName}} - {{.Usage}} USAGE: - {{.HelpName}}{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{if .Category}} + {{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}}{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Category}} CATEGORY: {{.Category}}{{end}}{{if .Description}} @@ -64,10 +64,10 @@ OPTIONS: // cli.go uses text/template to render templates. You can // render custom help text by setting this variable. var SubcommandHelpTemplate = `NAME: - {{.HelpName}} - {{.Usage}} + {{.HelpName}} - {{if .Description}}{{.Description}}{{else}}{{.Usage}}{{end}} USAGE: - {{.HelpName}} command{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}} + {{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}} command{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}} COMMANDS:{{range .VisibleCategories}}{{if .Name}} {{.Name}}:{{end}}{{range .VisibleCommands}} @@ -112,17 +112,42 @@ var helpSubcommand = Command{ // Prints help for the App or Command type helpPrinter func(w io.Writer, templ string, data interface{}) +// Prints help for the App or Command with custom template function. +type helpPrinterCustom func(w io.Writer, templ string, data interface{}, customFunc map[string]interface{}) + // HelpPrinter is a function that writes the help output. If not set a default // is used. The function signature is: // func(w io.Writer, templ string, data interface{}) var HelpPrinter helpPrinter = printHelp +// HelpPrinterCustom is same as HelpPrinter but +// takes a custom function for template function map. +var HelpPrinterCustom helpPrinterCustom = printHelpCustom + // VersionPrinter prints the version for the App var VersionPrinter = printVersion +// ShowAppHelpAndExit - Prints the list of subcommands for the app and exits with exit code. +func ShowAppHelpAndExit(c *Context, exitCode int) { + ShowAppHelp(c) + os.Exit(exitCode) +} + // ShowAppHelp is an action that displays the help. -func ShowAppHelp(c *Context) error { - HelpPrinter(c.App.Writer, AppHelpTemplate, c.App) +func ShowAppHelp(c *Context) (err error) { + if c.App.CustomAppHelpTemplate == "" { + HelpPrinter(c.App.Writer, AppHelpTemplate, c.App) + return + } + customAppData := func() map[string]interface{} { + if c.App.ExtraInfo == nil { + return nil + } + return map[string]interface{}{ + "ExtraInfo": c.App.ExtraInfo, + } + } + HelpPrinterCustom(c.App.Writer, c.App.CustomAppHelpTemplate, c.App, customAppData()) return nil } @@ -138,6 +163,12 @@ func DefaultAppComplete(c *Context) { } } +// ShowCommandHelpAndExit - exits with code after showing help +func ShowCommandHelpAndExit(c *Context, command string, code int) { + ShowCommandHelp(c, command) + os.Exit(code) +} + // ShowCommandHelp prints help for the given command func ShowCommandHelp(ctx *Context, command string) error { // show the subcommand help for a command with subcommands @@ -148,7 +179,11 @@ func ShowCommandHelp(ctx *Context, command string) error { for _, c := range ctx.App.Commands { if c.HasName(command) { - HelpPrinter(ctx.App.Writer, CommandHelpTemplate, c) + if c.CustomHelpTemplate != "" { + HelpPrinterCustom(ctx.App.Writer, c.CustomHelpTemplate, c, nil) + } else { + HelpPrinter(ctx.App.Writer, CommandHelpTemplate, c) + } return nil } } @@ -191,10 +226,15 @@ func ShowCommandCompletions(ctx *Context, command string) { } } -func printHelp(out io.Writer, templ string, data interface{}) { +func printHelpCustom(out io.Writer, templ string, data interface{}, customFunc map[string]interface{}) { funcMap := template.FuncMap{ "join": strings.Join, } + if customFunc != nil { + for key, value := range customFunc { + funcMap[key] = value + } + } w := tabwriter.NewWriter(out, 1, 8, 2, ' ', 0) t := template.Must(template.New("help").Funcs(funcMap).Parse(templ)) @@ -210,10 +250,14 @@ func printHelp(out io.Writer, templ string, data interface{}) { w.Flush() } +func printHelp(out io.Writer, templ string, data interface{}) { + printHelpCustom(out, templ, data, nil) +} + func checkVersion(c *Context) bool { found := false - if VersionFlag.Name != "" { - eachName(VersionFlag.Name, func(name string) { + if VersionFlag.GetName() != "" { + eachName(VersionFlag.GetName(), func(name string) { if c.GlobalBool(name) || c.Bool(name) { found = true } @@ -224,8 +268,8 @@ func checkVersion(c *Context) bool { func checkHelp(c *Context) bool { found := false - if HelpFlag.Name != "" { - eachName(HelpFlag.Name, func(name string) { + if HelpFlag.GetName() != "" { + eachName(HelpFlag.GetName(), func(name string) { if c.GlobalBool(name) || c.Bool(name) { found = true } @@ -260,7 +304,7 @@ func checkShellCompleteFlag(a *App, arguments []string) (bool, []string) { pos := len(arguments) - 1 lastArg := arguments[pos] - if lastArg != "--"+BashCompletionFlag.Name { + if lastArg != "--"+BashCompletionFlag.GetName() { return false, arguments } diff --git a/vendor/vendor.json b/vendor/vendor.json index 135894766..8be10b94f 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -670,10 +670,10 @@ "revisionTime": "2017-02-13T14:20:43Z" }, { - "checksumSHA1": "brhONOPp4CSdTZf5uEtcH+FpFUI=", + "checksumSHA1": "Yx1MU40fyGe7hhqW9+dkv8kXa60=", "path": "gopkg.in/urfave/cli.v1", - "revision": "0bdeddeeb0f650497d603c4ad7b20cfe685682f6", - "revisionTime": "2016-11-22T04:36:10Z" + "revision": "cfb38830724cc34fedffe9a2a29fb54fa9169cd1", + "revisionTime": "2017-08-11T01:42:03Z" } ], "rootPath": "github.com/ethereum/go-ethereum" |