Skip to content

Commit

Permalink
cmd: implement MigrateFlags as App.Before hook
Browse files Browse the repository at this point in the history
This makes it unnecessary to wrap each action function with
utils.MigrateFlags in source code.
  • Loading branch information
fjl committed Jun 25, 2022
1 parent 1d93f3b commit 1dfc46f
Show file tree
Hide file tree
Showing 15 changed files with 119 additions and 86 deletions.
2 changes: 1 addition & 1 deletion cmd/abigen/main.go
Expand Up @@ -96,7 +96,7 @@ func init() {
langFlag,
aliasFlag,
}
app.Action = utils.MigrateFlags(abigen)
app.Action = abigen
}

func abigen(c *cli.Context) error {
Expand Down
6 changes: 3 additions & 3 deletions cmd/checkpoint-admin/exec.go
Expand Up @@ -49,7 +49,7 @@ var commandDeploy = &cli.Command{
signersFlag,
thresholdFlag,
},
Action: utils.MigrateFlags(deploy),
Action: deploy,
}

var commandSign = &cli.Command{
Expand All @@ -63,7 +63,7 @@ var commandSign = &cli.Command{
hashFlag,
oracleFlag,
},
Action: utils.MigrateFlags(sign),
Action: sign,
}

var commandPublish = &cli.Command{
Expand All @@ -76,7 +76,7 @@ var commandPublish = &cli.Command{
indexFlag,
signaturesFlag,
},
Action: utils.MigrateFlags(publish),
Action: publish,
}

// deploy deploys the checkpoint registrar contract.
Expand Down
3 changes: 1 addition & 2 deletions cmd/checkpoint-admin/status.go
Expand Up @@ -19,7 +19,6 @@ package main
import (
"fmt"

"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/urfave/cli/v2"
)
Expand All @@ -30,7 +29,7 @@ var commandStatus = &cli.Command{
Flags: []cli.Flag{
nodeURLFlag,
},
Action: utils.MigrateFlags(status),
Action: status,
}

// status fetches the admin list of specified registrar contract.
Expand Down
10 changes: 5 additions & 5 deletions cmd/clef/main.go
Expand Up @@ -135,7 +135,7 @@ var (
Usage: "Mechanism to test interface between Clef and UI. Requires 'stdio-ui'.",
}
initCommand = &cli.Command{
Action: utils.MigrateFlags(initializeSecrets),
Action: initializeSecrets,
Name: "init",
Usage: "Initialize the signer, generate secret storage",
ArgsUsage: "",
Expand All @@ -148,7 +148,7 @@ The init command generates a master seed which Clef can use to store credentials
the rule-engine to work.`,
}
attestCommand = &cli.Command{
Action: utils.MigrateFlags(attestFile),
Action: attestFile,
Name: "attest",
Usage: "Attest that a js-file is to be used",
ArgsUsage: "<sha256sum>",
Expand All @@ -165,7 +165,7 @@ Whenever you make an edit to the rule file, you need to use attestation to tell
Clef that the file is 'safe' to execute.`,
}
setCredentialCommand = &cli.Command{
Action: utils.MigrateFlags(setCredential),
Action: setCredential,
Name: "setpw",
Usage: "Store a credential for a keystore file",
ArgsUsage: "<address>",
Expand All @@ -178,7 +178,7 @@ Clef that the file is 'safe' to execute.`,
The setpw command stores a password for a given address (keyfile).
`}
delCredentialCommand = &cli.Command{
Action: utils.MigrateFlags(removeCredential),
Action: removeCredential,
Name: "delpw",
Usage: "Remove a credential for a keystore file",
ArgsUsage: "<address>",
Expand All @@ -191,7 +191,7 @@ The setpw command stores a password for a given address (keyfile).
The delpw command removes a password for a given address (keyfile).
`}
newAccountCommand = &cli.Command{
Action: utils.MigrateFlags(newAccount),
Action: newAccount,
Name: "newaccount",
Usage: "Create a new account",
ArgsUsage: "",
Expand Down
2 changes: 2 additions & 0 deletions cmd/devp2p/main.go
Expand Up @@ -22,6 +22,7 @@ import (
"path/filepath"

"github.com/ethereum/go-ethereum/internal/debug"
"github.com/ethereum/go-ethereum/internal/flags"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/params"
"github.com/urfave/cli/v2"
Expand All @@ -44,6 +45,7 @@ func init() {
// Set up the CLI app.
app.Flags = append(app.Flags, debug.Flags...)
app.Before = func(ctx *cli.Context) error {
flags.MigrateGlobalFlags(ctx)
return debug.Setup(ctx)
}
app.After = func(ctx *cli.Context) error {
Expand Down
10 changes: 5 additions & 5 deletions cmd/geth/accountcmd.go
Expand Up @@ -45,7 +45,7 @@ passwordfile as argument containing the wallet password in plaintext.`,
Name: "import",
Usage: "Import Ethereum presale wallet",
ArgsUsage: "<keyFile>",
Action: utils.MigrateFlags(importWallet),
Action: importWallet,
Flags: []cli.Flag{
utils.DataDirFlag,
utils.KeyStoreDirFlag,
Expand Down Expand Up @@ -89,7 +89,7 @@ Make sure you backup your keys regularly.`,
{
Name: "list",
Usage: "Print summary of existing accounts",
Action: utils.MigrateFlags(accountList),
Action: accountList,
Flags: []cli.Flag{
utils.DataDirFlag,
utils.KeyStoreDirFlag,
Expand All @@ -100,7 +100,7 @@ Print a short summary of all accounts`,
{
Name: "new",
Usage: "Create a new account",
Action: utils.MigrateFlags(accountCreate),
Action: accountCreate,
Flags: []cli.Flag{
utils.DataDirFlag,
utils.KeyStoreDirFlag,
Expand All @@ -125,7 +125,7 @@ password to file or expose in any other way.
{
Name: "update",
Usage: "Update an existing account",
Action: utils.MigrateFlags(accountUpdate),
Action: accountUpdate,
ArgsUsage: "<address>",
Flags: []cli.Flag{
utils.DataDirFlag,
Expand Down Expand Up @@ -154,7 +154,7 @@ changing your password is only possible interactively.
{
Name: "import",
Usage: "Import a private key into a new account",
Action: utils.MigrateFlags(accountImport),
Action: accountImport,
Flags: []cli.Flag{
utils.DataDirFlag,
utils.KeyStoreDirFlag,
Expand Down
14 changes: 7 additions & 7 deletions cmd/geth/chaincmd.go
Expand Up @@ -43,7 +43,7 @@ import (

var (
initCommand = &cli.Command{
Action: utils.MigrateFlags(initGenesis),
Action: initGenesis,
Name: "init",
Usage: "Bootstrap and initialize a new genesis block",
ArgsUsage: "<genesisPath>",
Expand All @@ -56,7 +56,7 @@ participating.
It expects the genesis file as argument.`,
}
dumpGenesisCommand = &cli.Command{
Action: utils.MigrateFlags(dumpGenesis),
Action: dumpGenesis,
Name: "dumpgenesis",
Usage: "Dumps genesis block JSON configuration to stdout",
ArgsUsage: "",
Expand All @@ -65,7 +65,7 @@ It expects the genesis file as argument.`,
The dumpgenesis command dumps the genesis block configuration in JSON format to stdout.`,
}
importCommand = &cli.Command{
Action: utils.MigrateFlags(importChain),
Action: importChain,
Name: "import",
Usage: "Import a blockchain file",
ArgsUsage: "<filename> (<filename 2> ... <filename N>) ",
Expand Down Expand Up @@ -100,7 +100,7 @@ If only one file is used, import error will result in failure. If several files
processing will proceed even if an individual RLP-file import failure occurs.`,
}
exportCommand = &cli.Command{
Action: utils.MigrateFlags(exportChain),
Action: exportChain,
Name: "export",
Usage: "Export blockchain into file",
ArgsUsage: "<filename> [<blockNumFirst> <blockNumLast>]",
Expand All @@ -116,7 +116,7 @@ if already existing. If the file ends with .gz, the output will
be gzipped.`,
}
importPreimagesCommand = &cli.Command{
Action: utils.MigrateFlags(importPreimages),
Action: importPreimages,
Name: "import-preimages",
Usage: "Import the preimage database from an RLP stream",
ArgsUsage: "<datafile>",
Expand All @@ -130,7 +130,7 @@ It's deprecated, please use "geth db import" instead.
`,
}
exportPreimagesCommand = &cli.Command{
Action: utils.MigrateFlags(exportPreimages),
Action: exportPreimages,
Name: "export-preimages",
Usage: "Export the preimage database into an RLP stream",
ArgsUsage: "<dumpfile>",
Expand All @@ -144,7 +144,7 @@ It's deprecated, please use "geth db export" instead.
`,
}
dumpCommand = &cli.Command{
Action: utils.MigrateFlags(dump),
Action: dump,
Name: "dump",
Usage: "Dump a specific block from storage",
ArgsUsage: "[? <blockHash> | <blockNum>]",
Expand Down
2 changes: 1 addition & 1 deletion cmd/geth/config.go
Expand Up @@ -45,7 +45,7 @@ import (

var (
dumpConfigCommand = &cli.Command{
Action: utils.MigrateFlags(dumpConfig),
Action: dumpConfig,
Name: "dumpconfig",
Usage: "Show configuration values",
ArgsUsage: "",
Expand Down
6 changes: 3 additions & 3 deletions cmd/geth/consolecmd.go
Expand Up @@ -31,7 +31,7 @@ var (
consoleFlags = []cli.Flag{utils.JSpathFlag, utils.ExecFlag, utils.PreloadJSFlag}

consoleCommand = &cli.Command{
Action: utils.MigrateFlags(localConsole),
Action: localConsole,
Name: "console",
Usage: "Start an interactive JavaScript environment",
Flags: utils.GroupFlags(nodeFlags, rpcFlags, consoleFlags),
Expand All @@ -42,7 +42,7 @@ See https://geth.ethereum.org/docs/interface/javascript-console.`,
}

attachCommand = &cli.Command{
Action: utils.MigrateFlags(remoteConsole),
Action: remoteConsole,
Name: "attach",
Usage: "Start an interactive JavaScript environment (connect to node)",
ArgsUsage: "[endpoint]",
Expand All @@ -55,7 +55,7 @@ This command allows to open a console on a running geth node.`,
}

javascriptCommand = &cli.Command{
Action: utils.MigrateFlags(ephemeralConsole),
Action: ephemeralConsole,
Name: "js",
Usage: "(DEPRECATED) Execute the specified JavaScript files",
ArgsUsage: "<jsfile> [jsfile...]",
Expand Down
28 changes: 14 additions & 14 deletions cmd/geth/dbcmd.go
Expand Up @@ -45,7 +45,7 @@ import (

var (
removedbCommand = &cli.Command{
Action: utils.MigrateFlags(removeDB),
Action: removeDB,
Name: "removedb",
Usage: "Remove blockchain and state databases",
ArgsUsage: "",
Expand Down Expand Up @@ -74,7 +74,7 @@ Remove blockchain and state databases`,
},
}
dbInspectCmd = &cli.Command{
Action: utils.MigrateFlags(inspect),
Action: inspect,
Name: "inspect",
ArgsUsage: "<prefix> <start>",
Flags: utils.GroupFlags([]cli.Flag{
Expand All @@ -84,7 +84,7 @@ Remove blockchain and state databases`,
Description: `This commands iterates the entire database. If the optional 'prefix' and 'start' arguments are provided, then the iteration is limited to the given subset of data.`,
}
dbCheckStateContentCmd = &cli.Command{
Action: utils.MigrateFlags(checkStateContent),
Action: checkStateContent,
Name: "check-state-content",
ArgsUsage: "<start (optional)>",
Flags: utils.GroupFlags(utils.NetworkFlags, utils.DatabasePathFlags),
Expand All @@ -94,15 +94,15 @@ For each trie node encountered, it checks that the key corresponds to the keccak
a data corruption.`,
}
dbStatCmd = &cli.Command{
Action: utils.MigrateFlags(dbStats),
Action: dbStats,
Name: "stats",
Usage: "Print leveldb statistics",
Flags: utils.GroupFlags([]cli.Flag{
utils.SyncModeFlag,
}, utils.NetworkFlags, utils.DatabasePathFlags),
}
dbCompactCmd = &cli.Command{
Action: utils.MigrateFlags(dbCompact),
Action: dbCompact,
Name: "compact",
Usage: "Compact leveldb database. WARNING: May take a very long time",
Flags: utils.GroupFlags([]cli.Flag{
Expand All @@ -115,7 +115,7 @@ WARNING: This operation may take a very long time to finish, and may cause datab
corruption if it is aborted during execution'!`,
}
dbGetCmd = &cli.Command{
Action: utils.MigrateFlags(dbGet),
Action: dbGet,
Name: "get",
Usage: "Show the value of a database key",
ArgsUsage: "<hex-encoded key>",
Expand All @@ -125,7 +125,7 @@ corruption if it is aborted during execution'!`,
Description: "This command looks up the specified database key from the database.",
}
dbDeleteCmd = &cli.Command{
Action: utils.MigrateFlags(dbDelete),
Action: dbDelete,
Name: "delete",
Usage: "Delete a database key (WARNING: may corrupt your database)",
ArgsUsage: "<hex-encoded key>",
Expand All @@ -136,7 +136,7 @@ corruption if it is aborted during execution'!`,
WARNING: This is a low-level operation which may cause database corruption!`,
}
dbPutCmd = &cli.Command{
Action: utils.MigrateFlags(dbPut),
Action: dbPut,
Name: "put",
Usage: "Set the value of a database key (WARNING: may corrupt your database)",
ArgsUsage: "<hex-encoded key> <hex-encoded value>",
Expand All @@ -147,7 +147,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
WARNING: This is a low-level operation which may cause database corruption!`,
}
dbGetSlotsCmd = &cli.Command{
Action: utils.MigrateFlags(dbDumpTrie),
Action: dbDumpTrie,
Name: "dumptrie",
Usage: "Show the storage key/values of a given storage trie",
ArgsUsage: "<hex-encoded storage trie root> <hex-encoded start (optional)> <int max elements (optional)>",
Expand All @@ -157,7 +157,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
Description: "This command looks up the specified database key from the database.",
}
dbDumpFreezerIndex = &cli.Command{
Action: utils.MigrateFlags(freezerInspect),
Action: freezerInspect,
Name: "freezer-index",
Usage: "Dump out the index of a given freezer type",
ArgsUsage: "<type> <start (int)> <end (int)>",
Expand All @@ -167,7 +167,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
Description: "This command displays information about the freezer index.",
}
dbImportCmd = &cli.Command{
Action: utils.MigrateFlags(importLDBdata),
Action: importLDBdata,
Name: "import",
Usage: "Imports leveldb-data from an exported RLP dump.",
ArgsUsage: "<dumpfile> <start (optional)",
Expand All @@ -177,7 +177,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
Description: "The import command imports the specific chain data from an RLP encoded stream.",
}
dbExportCmd = &cli.Command{
Action: utils.MigrateFlags(exportChaindata),
Action: exportChaindata,
Name: "export",
Usage: "Exports the chain data into an RLP dump. If the <dumpfile> has .gz suffix, gzip compression will be used.",
ArgsUsage: "<type> <dumpfile>",
Expand All @@ -187,7 +187,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
Description: "Exports the specified chain data to an RLP encoded stream, optionally gzip-compressed.",
}
dbMetadataCmd = &cli.Command{
Action: utils.MigrateFlags(showMetaData),
Action: showMetaData,
Name: "metadata",
Usage: "Shows metadata about the chain status.",
Flags: utils.GroupFlags([]cli.Flag{
Expand All @@ -196,7 +196,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
Description: "Shows metadata about the chain status.",
}
dbMigrateFreezerCmd = &cli.Command{
Action: utils.MigrateFlags(freezerMigrate),
Action: freezerMigrate,
Name: "freezer-migrate",
Usage: "Migrate legacy parts of the freezer. (WARNING: may take a long time)",
ArgsUsage: "",
Expand Down

0 comments on commit 1dfc46f

Please sign in to comment.