Skip to content

Commit

Permalink
cmd/utils: move custom flag types to package internal/flags
Browse files Browse the repository at this point in the history
  • Loading branch information
fjl committed Jun 25, 2022
1 parent 3167b15 commit 3efd8fb
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 42 deletions.
2 changes: 1 addition & 1 deletion cmd/clef/main.go
Expand Up @@ -660,7 +660,7 @@ func signer(c *cli.Context) error {
// persistence requirements.
func DefaultConfigDir() string {
// Try to place the data folder in the user's home dir
home := utils.HomeDir()
home := flags.HomeDir()
if home != "" {
if runtime.GOOS == "darwin" {
return filepath.Join(home, "Library", "Signer")
Expand Down
5 changes: 2 additions & 3 deletions cmd/evm/main.go
Expand Up @@ -23,7 +23,6 @@ import (
"os"

"github.com/ethereum/go-ethereum/cmd/evm/internal/t8ntool"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/internal/flags"
"github.com/urfave/cli/v2"
)
Expand Down Expand Up @@ -65,12 +64,12 @@ var (
Usage: "gas limit for the evm",
Value: 10000000000,
}
PriceFlag = &utils.BigFlag{
PriceFlag = &flags.BigFlag{
Name: "price",
Usage: "price set for the evm",
Value: new(big.Int),
}
ValueFlag = &utils.BigFlag{
ValueFlag = &flags.BigFlag{
Name: "value",
Usage: "value set for the evm",
Value: new(big.Int),
Expand Down
5 changes: 3 additions & 2 deletions cmd/evm/runner.go
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/core/vm/runtime"
"github.com/ethereum/go-ethereum/eth/tracers/logger"
"github.com/ethereum/go-ethereum/internal/flags"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -205,8 +206,8 @@ func runCmd(ctx *cli.Context) error {
Origin: sender,
State: statedb,
GasLimit: initialGas,
GasPrice: utils.GlobalBig(ctx, PriceFlag.Name),
Value: utils.GlobalBig(ctx, ValueFlag.Name),
GasPrice: flags.GlobalBig(ctx, PriceFlag.Name),
Value: flags.GlobalBig(ctx, ValueFlag.Name),
Difficulty: genesisConfig.Difficulty,
Time: new(big.Int).SetUint64(genesisConfig.Timestamp),
Coinbase: genesisConfig.Coinbase,
Expand Down
2 changes: 1 addition & 1 deletion cmd/geth/config.go
Expand Up @@ -161,7 +161,7 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
cfg.Eth.OverrideGrayGlacier = new(big.Int).SetUint64(ctx.Uint64(utils.OverrideGrayGlacierFlag.Name))
}
if ctx.IsSet(utils.OverrideTerminalTotalDifficulty.Name) {
cfg.Eth.OverrideTerminalTotalDifficulty = utils.GlobalBig(ctx, utils.OverrideTerminalTotalDifficulty.Name)
cfg.Eth.OverrideTerminalTotalDifficulty = flags.GlobalBig(ctx, utils.OverrideTerminalTotalDifficulty.Name)
}
backend, eth := utils.RegisterEthService(stack, &cfg.Eth)
// Warn users to migrate if they have a legacy freezer format.
Expand Down
2 changes: 1 addition & 1 deletion cmd/geth/main.go
Expand Up @@ -437,7 +437,7 @@ func startNode(ctx *cli.Context, stack *node.Node, backend ethapi.Backend, isCon
utils.Fatalf("Ethereum service not running")
}
// Set the gas price to the limits from the CLI and start mining
gasprice := utils.GlobalBig(ctx, utils.MinerGasPriceFlag.Name)
gasprice := flags.GlobalBig(ctx, utils.MinerGasPriceFlag.Name)
ethBackend.TxPool().SetGasPrice(gasprice)
// start mining
threads := ctx.Int(utils.MinerThreadsFlag.Name)
Expand Down
36 changes: 18 additions & 18 deletions cmd/utils/flags.go
Expand Up @@ -78,28 +78,28 @@ import (

var (
// General settings
DataDirFlag = &DirectoryFlag{
DataDirFlag = &flags.DirectoryFlag{
Name: "datadir",
Usage: "Data directory for the databases and keystore",
Value: DirectoryString(node.DefaultDataDir()),
Value: flags.DirectoryString(node.DefaultDataDir()),
Category: flags.EthCategory,
}
RemoteDBFlag = &cli.StringFlag{
Name: "remotedb",
Usage: "URL for remote database",
Category: flags.LoggingCategory,
}
AncientFlag = &DirectoryFlag{
AncientFlag = &flags.DirectoryFlag{
Name: "datadir.ancient",
Usage: "Data directory for ancient chain segments (default = inside chaindata)",
Category: flags.EthCategory,
}
MinFreeDiskSpaceFlag = &DirectoryFlag{
MinFreeDiskSpaceFlag = &flags.DirectoryFlag{
Name: "datadir.minfreedisk",
Usage: "Minimum free disk space in MB, once reached triggers auto shut down (default = --cache.gc converted to MB, 0 = disabled)",
Category: flags.EthCategory,
}
KeyStoreDirFlag = &DirectoryFlag{
KeyStoreDirFlag = &flags.DirectoryFlag{
Name: "keystore",
Usage: "Directory for the keystore (default = inside the datadir)",
Category: flags.AccountCategory,
Expand Down Expand Up @@ -175,10 +175,10 @@ var (
Usage: "Custom node name",
Category: flags.NetworkingCategory,
}
DocRootFlag = DirectoryFlag{
DocRootFlag = &flags.DirectoryFlag{
Name: "docroot",
Usage: "Document Root for HTTPClient file scheme",
Value: DirectoryString(HomeDir()),
Value: flags.DirectoryString(flags.HomeDir()),
Category: flags.APICategory,
}
ExitWhenSyncedFlag = &cli.BoolFlag{
Expand Down Expand Up @@ -217,7 +217,7 @@ var (
}

defaultSyncMode = ethconfig.Defaults.SyncMode
SyncModeFlag = &TextMarshalerFlag{
SyncModeFlag = &flags.TextMarshalerFlag{
Name: "syncmode",
Usage: `Blockchain sync mode ("snap", "full" or "light")`,
Value: &defaultSyncMode,
Expand Down Expand Up @@ -267,7 +267,7 @@ var (
Usage: "Manually specify Gray Glacier fork-block, overriding the bundled setting",
Category: flags.EthCategory,
}
OverrideTerminalTotalDifficulty = &BigFlag{
OverrideTerminalTotalDifficulty = &flags.BigFlag{
Name: "override.terminaltotaldifficulty",
Usage: "Manually specify TerminalTotalDifficulty, overriding the bundled setting",
Category: flags.EthCategory,
Expand Down Expand Up @@ -327,7 +327,7 @@ var (
}

// Ethash settings
EthashCacheDirFlag = &DirectoryFlag{
EthashCacheDirFlag = &flags.DirectoryFlag{
Name: "ethash.cachedir",
Usage: "Directory to store the ethash verification caches (default = inside the datadir)",
Category: flags.EthashCategory,
Expand All @@ -349,10 +349,10 @@ var (
Usage: "Lock memory maps of recent ethash caches",
Category: flags.EthashCategory,
}
EthashDatasetDirFlag = &DirectoryFlag{
EthashDatasetDirFlag = &flags.DirectoryFlag{
Name: "ethash.dagdir",
Usage: "Directory to store the ethash mining DAGs",
Value: DirectoryString(ethconfig.Defaults.Ethash.DatasetDir),
Value: flags.DirectoryString(ethconfig.Defaults.Ethash.DatasetDir),
Category: flags.EthashCategory,
}
EthashDatasetsInMemoryFlag = &cli.IntFlag{
Expand Down Expand Up @@ -526,7 +526,7 @@ var (
Value: ethconfig.Defaults.Miner.GasCeil,
Category: flags.MinerCategory,
}
MinerGasPriceFlag = &BigFlag{
MinerGasPriceFlag = &flags.BigFlag{
Name: "miner.gasprice",
Usage: "Minimum gas price for mining a transaction",
Value: ethconfig.Defaults.Miner.GasPrice,
Expand Down Expand Up @@ -660,7 +660,7 @@ var (
Usage: "Disable the IPC-RPC server",
Category: flags.APICategory,
}
IPCPathFlag = &DirectoryFlag{
IPCPathFlag = &flags.DirectoryFlag{
Name: "ipcpath",
Usage: "Filename for IPC socket/pipe within the datadir (explicit paths escape it)",
Category: flags.APICategory,
Expand Down Expand Up @@ -837,10 +837,10 @@ var (
}

// Console
JSpathFlag = &DirectoryFlag{
JSpathFlag = &flags.DirectoryFlag{
Name: "jspath",
Usage: "JavaScript root path for `loadScript`",
Value: DirectoryString("."),
Value: flags.DirectoryString("."),
Category: flags.APICategory,
}

Expand Down Expand Up @@ -1632,7 +1632,7 @@ func setMiner(ctx *cli.Context, cfg *miner.Config) {
cfg.GasCeil = ctx.Uint64(MinerGasLimitFlag.Name)
}
if ctx.IsSet(MinerGasPriceFlag.Name) {
cfg.GasPrice = GlobalBig(ctx, MinerGasPriceFlag.Name)
cfg.GasPrice = flags.GlobalBig(ctx, MinerGasPriceFlag.Name)
}
if ctx.IsSet(MinerRecommitIntervalFlag.Name) {
cfg.Recommit = ctx.Duration(MinerRecommitIntervalFlag.Name)
Expand Down Expand Up @@ -1760,7 +1760,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
godebug.SetGCPercent(int(gogc))

if ctx.IsSet(SyncModeFlag.Name) {
cfg.SyncMode = *GlobalTextMarshaler(ctx, SyncModeFlag.Name).(*downloader.SyncMode)
cfg.SyncMode = *flags.GlobalTextMarshaler(ctx, SyncModeFlag.Name).(*downloader.SyncMode)
}
if ctx.IsSet(NetworkIdFlag.Name) {
cfg.NetworkId = ctx.Uint64(NetworkIdFlag.Name)
Expand Down
16 changes: 8 additions & 8 deletions cmd/utils/customflags.go → internal/flags/flags.go
@@ -1,20 +1,20 @@
// Copyright 2015 The go-ethereum Authors
// This file is part of go-ethereum.
// This file is part of the go-ethereum library.
//
// go-ethereum is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// 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.
//
// go-ethereum is distributed in the hope that it will be useful,
// 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 General Public License for more details.
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
// 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 utils
package flags

import (
"encoding"
Expand Down
16 changes: 8 additions & 8 deletions cmd/utils/customflags_test.go → internal/flags/flags_test.go
@@ -1,20 +1,20 @@
// Copyright 2015 The go-ethereum Authors
// This file is part of go-ethereum.
// This file is part of the go-ethereum library.
//
// go-ethereum is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// 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.
//
// go-ethereum is distributed in the hope that it will be useful,
// 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 General Public License for more details.
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
// 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 utils
package flags

import (
"os"
Expand Down

0 comments on commit 3efd8fb

Please sign in to comment.