ethereum / go-ethereum

Go implementation of the Ethereum protocol
https://geth.ethereum.org
GNU Lesser General Public License v3.0
47.75k stars 20.22k forks source link

internal/flags: fix "flag redefined" bug for alias on custom flags #30796

Closed gzliudan closed 4 days ago

gzliudan commented 6 days ago

If we define an alias for any of DirectoryString and BigFlag, geth or make test will panic with message flag redefined. For example:

    AncientFlag = &flags.DirectoryFlag{
        Name:     "datadir.ancient",
        Aliases:  []string{"datadir-ancient"},
        Usage:    "Root directory for ancient data (default = inside chaindata)",
        Category: flags.EthCategory,
    }

The geth will panic with the following message

geth flag redefined: datadir.ancient
panic: geth flag redefined: datadir.ancient

Some of test cases will fail with the following message when we run make test:

    test_cmd.go:261: (stderr:1) geth-test flag redefined: datadir.ancient
    test_cmd.go:261: (stderr:1) panic: geth-test flag redefined: datadir.ancient