• Felix Lange's avatar
    cmd/ethereum: improve command line interface · bae7e93a
    Felix Lange authored
    The ethereum command line interface is now structured using subcommands.
    These separate the different tasks it can perform.
    
    Almost all flag names are backwards compatible.
    
    The key tasks have not been ported to subcommands since they will be
    replaced by the new accounts infrastructure very soon.
    bae7e93a
command_test.go 1017 Bytes
package cli_test

import (
	"flag"
	"testing"

	"github.com/codegangsta/cli"
)

func TestCommandDoNotIgnoreFlags(t *testing.T) {
	app := cli.NewApp()
	set := flag.NewFlagSet("test", 0)
	test := []string{"blah", "blah", "-break"}
	set.Parse(test)

	c := cli.NewContext(app, set, set)

	command := cli.Command{
		Name:        "test-cmd",
		ShortName:   "tc",
		Usage:       "this is for testing",
		Description: "testing",
		Action:      func(_ *cli.Context) {},
	}
	err := command.Run(c)

	expect(t, err.Error(), "flag provided but not defined: -break")
}

func TestCommandIgnoreFlags(t *testing.T) {
	app := cli.NewApp()
	set := flag.NewFlagSet("test", 0)
	test := []string{"blah", "blah"}
	set.Parse(test)

	c := cli.NewContext(app, set, set)

	command := cli.Command{
		Name:            "test-cmd",
		ShortName:       "tc",
		Usage:           "this is for testing",
		Description:     "testing",
		Action:          func(_ *cli.Context) {},
		SkipFlagParsing: true,
	}
	err := command.Run(c)

	expect(t, err, nil)
}