mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 02:40:45 +00:00
This commit is contained in:
parent
6d7c36bb8f
commit
4716dc11af
3 changed files with 48 additions and 47 deletions
|
|
@ -92,7 +92,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func generate(c *cli.Context) error {
|
func generate(c *cli.Context) error {
|
||||||
utils.CheckExclusive(c, abiFlag, jsonFlag) // Only one source can be selected.
|
flags.CheckExclusive(c, abiFlag, jsonFlag) // Only one source can be selected.
|
||||||
|
|
||||||
if c.String(pkgFlag.Name) == "" {
|
if c.String(pkgFlag.Name) == "" {
|
||||||
utils.Fatalf("No destination package specified (--pkg)")
|
utils.Fatalf("No destination package specified (--pkg)")
|
||||||
|
|
|
||||||
|
|
@ -945,7 +945,7 @@ func setNodeUserIdent(ctx *cli.Context, cfg *node.Config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func setWhiteBlackListPeers(ctx *cli.Context, cfg *p2p.Config) {
|
func setWhiteBlackListPeers(ctx *cli.Context, cfg *p2p.Config) {
|
||||||
CheckExclusive(ctx, PeersWhitelistFlag, PeersBlacklistFlag)
|
flags.CheckExclusive(ctx, PeersWhitelistFlag, PeersBlacklistFlag)
|
||||||
|
|
||||||
// setup whitelist for peers
|
// setup whitelist for peers
|
||||||
if ctx.IsSet(PeersWhitelistFlag.Name) {
|
if ctx.IsSet(PeersWhitelistFlag.Name) {
|
||||||
|
|
@ -1195,7 +1195,7 @@ func setWS(ctx *cli.Context, cfg *node.Config) {
|
||||||
// setIPC creates an IPC path configuration from the set command line flags,
|
// setIPC creates an IPC path configuration from the set command line flags,
|
||||||
// returning an empty string if IPC was explicitly disabled, or the set path.
|
// returning an empty string if IPC was explicitly disabled, or the set path.
|
||||||
func setIPC(ctx *cli.Context, cfg *node.Config) {
|
func setIPC(ctx *cli.Context, cfg *node.Config) {
|
||||||
CheckExclusive(ctx, IPCDisabledFlag, IPCPathFlag)
|
flags.CheckExclusive(ctx, IPCDisabledFlag, IPCPathFlag)
|
||||||
switch {
|
switch {
|
||||||
case ctx.Bool(IPCDisabledFlag.Name):
|
case ctx.Bool(IPCDisabledFlag.Name):
|
||||||
cfg.IPCPath = ""
|
cfg.IPCPath = ""
|
||||||
|
|
@ -1323,7 +1323,7 @@ func SetP2PConfig(ctx *cli.Context, cfg *p2p.Config) {
|
||||||
cfg.NoDiscovery = true
|
cfg.NoDiscovery = true
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckExclusive(ctx, DiscoveryV5Flag, NoDiscoverFlag)
|
flags.CheckExclusive(ctx, DiscoveryV5Flag, NoDiscoverFlag)
|
||||||
cfg.DiscoveryV5 = ctx.Bool(DiscoveryV5Flag.Name)
|
cfg.DiscoveryV5 = ctx.Bool(DiscoveryV5Flag.Name)
|
||||||
|
|
||||||
if netrestrict := ctx.String(NetrestrictFlag.Name); netrestrict != "" {
|
if netrestrict := ctx.String(NetrestrictFlag.Name); netrestrict != "" {
|
||||||
|
|
@ -1345,7 +1345,7 @@ func SetP2PConfig(ctx *cli.Context, cfg *p2p.Config) {
|
||||||
|
|
||||||
// SetNodeConfig applies node-related command line flags to the config.
|
// SetNodeConfig applies node-related command line flags to the config.
|
||||||
func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
|
func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
|
||||||
CheckExclusive(ctx, Enable0xPrefixFlag, EnableXDCPrefixFlag)
|
flags.CheckExclusive(ctx, Enable0xPrefixFlag, EnableXDCPrefixFlag)
|
||||||
SetP2PConfig(ctx, &cfg.P2P)
|
SetP2PConfig(ctx, &cfg.P2P)
|
||||||
setIPC(ctx, cfg)
|
setIPC(ctx, cfg)
|
||||||
setHTTP(ctx, cfg)
|
setHTTP(ctx, cfg)
|
||||||
|
|
@ -1468,47 +1468,6 @@ func setTxPool(ctx *cli.Context, cfg *txpool.Config) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckExclusive verifies that only a single isntance of the provided flags was
|
|
||||||
// set by the user. Each flag might optionally be followed by a string type to
|
|
||||||
// specialize it further.
|
|
||||||
func CheckExclusive(ctx *cli.Context, args ...interface{}) {
|
|
||||||
set := make([]string, 0, 1)
|
|
||||||
for i := 0; i < len(args); i++ {
|
|
||||||
// Make sure the next argument is a flag and skip if not set
|
|
||||||
flag, ok := args[i].(cli.Flag)
|
|
||||||
if !ok {
|
|
||||||
panic(fmt.Sprintf("invalid argument, not cli.Flag type: %T", args[i]))
|
|
||||||
}
|
|
||||||
// Check if next arg extends current and expand its name if so
|
|
||||||
name := flag.Names()[0]
|
|
||||||
|
|
||||||
if i+1 < len(args) {
|
|
||||||
switch option := args[i+1].(type) {
|
|
||||||
case string:
|
|
||||||
// Extended flag check, make sure value set doesn't conflict with passed in option
|
|
||||||
if ctx.String(flag.Names()[0]) == option {
|
|
||||||
name += "=" + option
|
|
||||||
set = append(set, "--"+name)
|
|
||||||
}
|
|
||||||
// shift arguments and continue
|
|
||||||
i++
|
|
||||||
continue
|
|
||||||
|
|
||||||
case cli.Flag:
|
|
||||||
default:
|
|
||||||
panic(fmt.Sprintf("invalid argument, not cli.Flag or string extension: %T", args[i+1]))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Mark the flag if it's set
|
|
||||||
if ctx.IsSet(flag.Names()[0]) {
|
|
||||||
set = append(set, "--"+name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(set) > 1 {
|
|
||||||
Fatalf("Flags %v can't be used at the same time", strings.Join(set, ", "))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func SetXDCXConfig(ctx *cli.Context, cfg *XDCx.Config, XDCDataDir string) {
|
func SetXDCXConfig(ctx *cli.Context, cfg *XDCx.Config, XDCDataDir string) {
|
||||||
if ctx.IsSet(XDCXDataDirFlag.Name) {
|
if ctx.IsSet(XDCXDataDirFlag.Name) {
|
||||||
log.Warn("The flag XDCx-datadir or XDCx.datadir is deprecated, please remove this flag")
|
log.Warn("The flag XDCx-datadir or XDCx.datadir is deprecated, please remove this flag")
|
||||||
|
|
@ -1539,7 +1498,7 @@ func SetXDCXConfig(ctx *cli.Context, cfg *XDCx.Config, XDCDataDir string) {
|
||||||
// SetEthConfig applies eth-related command line flags to the config.
|
// SetEthConfig applies eth-related command line flags to the config.
|
||||||
func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
|
func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
|
||||||
// Avoid conflicting network flags
|
// Avoid conflicting network flags
|
||||||
CheckExclusive(ctx, MainnetFlag, TestnetFlag, DevnetFlag, DeveloperFlag)
|
flags.CheckExclusive(ctx, MainnetFlag, TestnetFlag, DevnetFlag, DeveloperFlag)
|
||||||
|
|
||||||
ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
|
ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
|
||||||
setEtherbase(ctx, ks, cfg)
|
setEtherbase(ctx, ks, cfg)
|
||||||
|
|
|
||||||
|
|
@ -295,3 +295,45 @@ func CheckEnvVars(ctx *cli.Context, flags []cli.Flag, prefix string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CheckExclusive verifies that only a single instance of the provided flags was
|
||||||
|
// set by the user. Each flag might optionally be followed by a string type to
|
||||||
|
// specialize it further.
|
||||||
|
func CheckExclusive(ctx *cli.Context, args ...any) {
|
||||||
|
set := make([]string, 0, 1)
|
||||||
|
for i := 0; i < len(args); i++ {
|
||||||
|
// Make sure the next argument is a flag and skip if not set
|
||||||
|
flag, ok := args[i].(cli.Flag)
|
||||||
|
if !ok {
|
||||||
|
panic(fmt.Sprintf("invalid argument, not cli.Flag type: %T", args[i]))
|
||||||
|
}
|
||||||
|
// Check if next arg extends current and expand its name if so
|
||||||
|
name := flag.Names()[0]
|
||||||
|
|
||||||
|
if i+1 < len(args) {
|
||||||
|
switch option := args[i+1].(type) {
|
||||||
|
case string:
|
||||||
|
// Extended flag check, make sure value set doesn't conflict with passed in option
|
||||||
|
if ctx.String(flag.Names()[0]) == option {
|
||||||
|
name += "=" + option
|
||||||
|
set = append(set, "--"+name)
|
||||||
|
}
|
||||||
|
// shift arguments and continue
|
||||||
|
i++
|
||||||
|
continue
|
||||||
|
|
||||||
|
case cli.Flag:
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("invalid argument, not cli.Flag or string extension: %T", args[i+1]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Mark the flag if it's set
|
||||||
|
if ctx.IsSet(flag.Names()[0]) {
|
||||||
|
set = append(set, "--"+name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(set) > 1 {
|
||||||
|
fmt.Fprintf(os.Stderr, "Flags %v can't be used at the same time", strings.Join(set, ", "))
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue