Skip to content

Commit 1ed8b7d

Browse files
authored
cmd: use flags.Merge for grouping flags (#25392)
1 parent b2be5f9 commit 1ed8b7d

File tree

7 files changed

+40
-45
lines changed

7 files changed

+40
-45
lines changed

cmd/geth/chaincmd.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/ethereum/go-ethereum/core/types"
3636
"github.com/ethereum/go-ethereum/crypto"
3737
"github.com/ethereum/go-ethereum/ethdb"
38+
"github.com/ethereum/go-ethereum/internal/flags"
3839
"github.com/ethereum/go-ethereum/log"
3940
"github.com/ethereum/go-ethereum/metrics"
4041
"github.com/ethereum/go-ethereum/node"
@@ -69,7 +70,7 @@ The dumpgenesis command dumps the genesis block configuration in JSON format to
6970
Name: "import",
7071
Usage: "Import a blockchain file",
7172
ArgsUsage: "<filename> (<filename 2> ... <filename N>) ",
72-
Flags: append([]cli.Flag{
73+
Flags: flags.Merge([]cli.Flag{
7374
utils.CacheFlag,
7475
utils.SyncModeFlag,
7576
utils.GCModeFlag,
@@ -91,7 +92,7 @@ The dumpgenesis command dumps the genesis block configuration in JSON format to
9192
utils.MetricsInfluxDBBucketFlag,
9293
utils.MetricsInfluxDBOrganizationFlag,
9394
utils.TxLookupLimitFlag,
94-
}, utils.DatabasePathFlags...),
95+
}, utils.DatabasePathFlags),
9596
Description: `
9697
The import command imports blocks from an RLP-encoded form. The form can be one file
9798
with several RLP-encoded blocks, or several files can be used.
@@ -104,10 +105,10 @@ processing will proceed even if an individual RLP-file import failure occurs.`,
104105
Name: "export",
105106
Usage: "Export blockchain into file",
106107
ArgsUsage: "<filename> [<blockNumFirst> <blockNumLast>]",
107-
Flags: append([]cli.Flag{
108+
Flags: flags.Merge([]cli.Flag{
108109
utils.CacheFlag,
109110
utils.SyncModeFlag,
110-
}, utils.DatabasePathFlags...),
111+
}, utils.DatabasePathFlags),
111112
Description: `
112113
Requires a first argument of the file to write to.
113114
Optional second and third arguments control the first and
@@ -120,10 +121,10 @@ be gzipped.`,
120121
Name: "import-preimages",
121122
Usage: "Import the preimage database from an RLP stream",
122123
ArgsUsage: "<datafile>",
123-
Flags: append([]cli.Flag{
124+
Flags: flags.Merge([]cli.Flag{
124125
utils.CacheFlag,
125126
utils.SyncModeFlag,
126-
}, utils.DatabasePathFlags...),
127+
}, utils.DatabasePathFlags),
127128
Description: `
128129
The import-preimages command imports hash preimages from an RLP encoded stream.
129130
It's deprecated, please use "geth db import" instead.
@@ -134,10 +135,10 @@ It's deprecated, please use "geth db import" instead.
134135
Name: "export-preimages",
135136
Usage: "Export the preimage database into an RLP stream",
136137
ArgsUsage: "<dumpfile>",
137-
Flags: append([]cli.Flag{
138+
Flags: flags.Merge([]cli.Flag{
138139
utils.CacheFlag,
139140
utils.SyncModeFlag,
140-
}, utils.DatabasePathFlags...),
141+
}, utils.DatabasePathFlags),
141142
Description: `
142143
The export-preimages command exports hash preimages to an RLP encoded stream.
143144
It's deprecated, please use "geth db export" instead.
@@ -148,15 +149,15 @@ It's deprecated, please use "geth db export" instead.
148149
Name: "dump",
149150
Usage: "Dump a specific block from storage",
150151
ArgsUsage: "[? <blockHash> | <blockNum>]",
151-
Flags: append([]cli.Flag{
152+
Flags: flags.Merge([]cli.Flag{
152153
utils.CacheFlag,
153154
utils.IterativeOutputFlag,
154155
utils.ExcludeCodeFlag,
155156
utils.ExcludeStorageFlag,
156157
utils.IncludeIncompletesFlag,
157158
utils.StartKeyFlag,
158159
utils.DumpLimitFlag,
159-
}, utils.DatabasePathFlags...),
160+
}, utils.DatabasePathFlags),
160161
Description: `
161162
This command dumps out the state for a given block (or latest, if none provided).
162163
`,

cmd/geth/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ var (
4949
Name: "dumpconfig",
5050
Usage: "Show configuration values",
5151
ArgsUsage: "",
52-
Flags: utils.GroupFlags(nodeFlags, rpcFlags),
52+
Flags: flags.Merge(nodeFlags, rpcFlags),
5353
Description: `The dumpconfig command shows configuration values.`,
5454
}
5555

cmd/geth/consolecmd.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
"github.com/ethereum/go-ethereum/cmd/utils"
2424
"github.com/ethereum/go-ethereum/console"
25+
"github.com/ethereum/go-ethereum/internal/flags"
2526
"github.com/ethereum/go-ethereum/node"
2627
"github.com/ethereum/go-ethereum/rpc"
2728
"github.com/urfave/cli/v2"
@@ -34,7 +35,7 @@ var (
3435
Action: localConsole,
3536
Name: "console",
3637
Usage: "Start an interactive JavaScript environment",
37-
Flags: utils.GroupFlags(nodeFlags, rpcFlags, consoleFlags),
38+
Flags: flags.Merge(nodeFlags, rpcFlags, consoleFlags),
3839
Description: `
3940
The Geth console is an interactive shell for the JavaScript runtime environment
4041
which exposes a node admin interface as well as the Ðapp JavaScript API.
@@ -46,7 +47,7 @@ See https://geth.ethereum.org/docs/interface/javascript-console.`,
4647
Name: "attach",
4748
Usage: "Start an interactive JavaScript environment (connect to node)",
4849
ArgsUsage: "[endpoint]",
49-
Flags: utils.GroupFlags([]cli.Flag{utils.DataDirFlag}, consoleFlags),
50+
Flags: flags.Merge([]cli.Flag{utils.DataDirFlag}, consoleFlags),
5051
Description: `
5152
The Geth console is an interactive shell for the JavaScript runtime environment
5253
which exposes a node admin interface as well as the Ðapp JavaScript API.
@@ -59,7 +60,7 @@ This command allows to open a console on a running geth node.`,
5960
Name: "js",
6061
Usage: "(DEPRECATED) Execute the specified JavaScript files",
6162
ArgsUsage: "<jsfile> [jsfile...]",
62-
Flags: utils.GroupFlags(nodeFlags, consoleFlags),
63+
Flags: flags.Merge(nodeFlags, consoleFlags),
6364
Description: `
6465
The JavaScript VM exposes a node admin interface as well as the Ðapp
6566
JavaScript API. See https://geth.ethereum.org/docs/interface/javascript-console`,

cmd/geth/dbcmd.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"github.com/ethereum/go-ethereum/core/types"
3838
"github.com/ethereum/go-ethereum/crypto"
3939
"github.com/ethereum/go-ethereum/ethdb"
40+
"github.com/ethereum/go-ethereum/internal/flags"
4041
"github.com/ethereum/go-ethereum/log"
4142
"github.com/ethereum/go-ethereum/trie"
4243
"github.com/olekukonko/tablewriter"
@@ -77,7 +78,7 @@ Remove blockchain and state databases`,
7778
Action: inspect,
7879
Name: "inspect",
7980
ArgsUsage: "<prefix> <start>",
80-
Flags: utils.GroupFlags([]cli.Flag{
81+
Flags: flags.Merge([]cli.Flag{
8182
utils.SyncModeFlag,
8283
}, utils.NetworkFlags, utils.DatabasePathFlags),
8384
Usage: "Inspect the storage size for each type of data in the database",
@@ -87,7 +88,7 @@ Remove blockchain and state databases`,
8788
Action: checkStateContent,
8889
Name: "check-state-content",
8990
ArgsUsage: "<start (optional)>",
90-
Flags: utils.GroupFlags(utils.NetworkFlags, utils.DatabasePathFlags),
91+
Flags: flags.Merge(utils.NetworkFlags, utils.DatabasePathFlags),
9192
Usage: "Verify that state data is cryptographically correct",
9293
Description: `This command iterates the entire database for 32-byte keys, looking for rlp-encoded trie nodes.
9394
For each trie node encountered, it checks that the key corresponds to the keccak256(value). If this is not true, this indicates
@@ -97,15 +98,15 @@ a data corruption.`,
9798
Action: dbStats,
9899
Name: "stats",
99100
Usage: "Print leveldb statistics",
100-
Flags: utils.GroupFlags([]cli.Flag{
101+
Flags: flags.Merge([]cli.Flag{
101102
utils.SyncModeFlag,
102103
}, utils.NetworkFlags, utils.DatabasePathFlags),
103104
}
104105
dbCompactCmd = &cli.Command{
105106
Action: dbCompact,
106107
Name: "compact",
107108
Usage: "Compact leveldb database. WARNING: May take a very long time",
108-
Flags: utils.GroupFlags([]cli.Flag{
109+
Flags: flags.Merge([]cli.Flag{
109110
utils.SyncModeFlag,
110111
utils.CacheFlag,
111112
utils.CacheDatabaseFlag,
@@ -119,7 +120,7 @@ corruption if it is aborted during execution'!`,
119120
Name: "get",
120121
Usage: "Show the value of a database key",
121122
ArgsUsage: "<hex-encoded key>",
122-
Flags: utils.GroupFlags([]cli.Flag{
123+
Flags: flags.Merge([]cli.Flag{
123124
utils.SyncModeFlag,
124125
}, utils.NetworkFlags, utils.DatabasePathFlags),
125126
Description: "This command looks up the specified database key from the database.",
@@ -129,7 +130,7 @@ corruption if it is aborted during execution'!`,
129130
Name: "delete",
130131
Usage: "Delete a database key (WARNING: may corrupt your database)",
131132
ArgsUsage: "<hex-encoded key>",
132-
Flags: utils.GroupFlags([]cli.Flag{
133+
Flags: flags.Merge([]cli.Flag{
133134
utils.SyncModeFlag,
134135
}, utils.NetworkFlags, utils.DatabasePathFlags),
135136
Description: `This command deletes the specified database key from the database.
@@ -140,7 +141,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
140141
Name: "put",
141142
Usage: "Set the value of a database key (WARNING: may corrupt your database)",
142143
ArgsUsage: "<hex-encoded key> <hex-encoded value>",
143-
Flags: utils.GroupFlags([]cli.Flag{
144+
Flags: flags.Merge([]cli.Flag{
144145
utils.SyncModeFlag,
145146
}, utils.NetworkFlags, utils.DatabasePathFlags),
146147
Description: `This command sets a given database key to the given value.
@@ -151,7 +152,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
151152
Name: "dumptrie",
152153
Usage: "Show the storage key/values of a given storage trie",
153154
ArgsUsage: "<hex-encoded storage trie root> <hex-encoded start (optional)> <int max elements (optional)>",
154-
Flags: utils.GroupFlags([]cli.Flag{
155+
Flags: flags.Merge([]cli.Flag{
155156
utils.SyncModeFlag,
156157
}, utils.NetworkFlags, utils.DatabasePathFlags),
157158
Description: "This command looks up the specified database key from the database.",
@@ -161,7 +162,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
161162
Name: "freezer-index",
162163
Usage: "Dump out the index of a given freezer type",
163164
ArgsUsage: "<type> <start (int)> <end (int)>",
164-
Flags: utils.GroupFlags([]cli.Flag{
165+
Flags: flags.Merge([]cli.Flag{
165166
utils.SyncModeFlag,
166167
}, utils.NetworkFlags, utils.DatabasePathFlags),
167168
Description: "This command displays information about the freezer index.",
@@ -171,7 +172,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
171172
Name: "import",
172173
Usage: "Imports leveldb-data from an exported RLP dump.",
173174
ArgsUsage: "<dumpfile> <start (optional)",
174-
Flags: utils.GroupFlags([]cli.Flag{
175+
Flags: flags.Merge([]cli.Flag{
175176
utils.SyncModeFlag,
176177
}, utils.NetworkFlags, utils.DatabasePathFlags),
177178
Description: "The import command imports the specific chain data from an RLP encoded stream.",
@@ -181,7 +182,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
181182
Name: "export",
182183
Usage: "Exports the chain data into an RLP dump. If the <dumpfile> has .gz suffix, gzip compression will be used.",
183184
ArgsUsage: "<type> <dumpfile>",
184-
Flags: utils.GroupFlags([]cli.Flag{
185+
Flags: flags.Merge([]cli.Flag{
185186
utils.SyncModeFlag,
186187
}, utils.NetworkFlags, utils.DatabasePathFlags),
187188
Description: "Exports the specified chain data to an RLP encoded stream, optionally gzip-compressed.",
@@ -190,7 +191,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
190191
Action: showMetaData,
191192
Name: "metadata",
192193
Usage: "Shows metadata about the chain status.",
193-
Flags: utils.GroupFlags([]cli.Flag{
194+
Flags: flags.Merge([]cli.Flag{
194195
utils.SyncModeFlag,
195196
}, utils.NetworkFlags, utils.DatabasePathFlags),
196197
Description: "Shows metadata about the chain status.",
@@ -200,7 +201,7 @@ WARNING: This is a low-level operation which may cause database corruption!`,
200201
Name: "freezer-migrate",
201202
Usage: "Migrate legacy parts of the freezer. (WARNING: may take a long time)",
202203
ArgsUsage: "",
203-
Flags: utils.GroupFlags([]cli.Flag{
204+
Flags: flags.Merge([]cli.Flag{
204205
utils.SyncModeFlag,
205206
}, utils.NetworkFlags, utils.DatabasePathFlags),
206207
Description: `The freezer-migrate command checks your database for receipts in a legacy format and updates those.

cmd/geth/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ var (
5858
// The app that holds all commands and flags.
5959
app = flags.NewApp(gitCommit, gitDate, "the go-ethereum command line interface")
6060
// flags that configure the node
61-
nodeFlags = utils.GroupFlags([]cli.Flag{
61+
nodeFlags = flags.Merge([]cli.Flag{
6262
utils.IdentityFlag,
6363
utils.UnlockedAccountFlag,
6464
utils.PasswordFileFlag,
@@ -243,7 +243,7 @@ func init() {
243243
}
244244
sort.Sort(cli.CommandsByName(app.Commands))
245245

246-
app.Flags = utils.GroupFlags(
246+
app.Flags = flags.Merge(
247247
nodeFlags,
248248
rpcFlags,
249249
consoleFlags,

cmd/geth/snapshot.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/ethereum/go-ethereum/core/state/snapshot"
3232
"github.com/ethereum/go-ethereum/core/types"
3333
"github.com/ethereum/go-ethereum/crypto"
34+
"github.com/ethereum/go-ethereum/internal/flags"
3435
"github.com/ethereum/go-ethereum/log"
3536
"github.com/ethereum/go-ethereum/rlp"
3637
"github.com/ethereum/go-ethereum/trie"
@@ -56,7 +57,7 @@ var (
5657
Usage: "Prune stale ethereum state data based on the snapshot",
5758
ArgsUsage: "<root>",
5859
Action: pruneState,
59-
Flags: utils.GroupFlags([]cli.Flag{
60+
Flags: flags.Merge([]cli.Flag{
6061
utils.CacheTrieJournalFlag,
6162
utils.BloomFilterSizeFlag,
6263
}, utils.NetworkFlags, utils.DatabasePathFlags),
@@ -80,7 +81,7 @@ the trie clean cache with default directory will be deleted.
8081
Usage: "Recalculate state hash based on the snapshot for verification",
8182
ArgsUsage: "<root>",
8283
Action: verifyState,
83-
Flags: utils.GroupFlags(utils.NetworkFlags, utils.DatabasePathFlags),
84+
Flags: flags.Merge(utils.NetworkFlags, utils.DatabasePathFlags),
8485
Description: `
8586
geth snapshot verify-state <state-root>
8687
will traverse the whole accounts and storages set based on the specified
@@ -93,7 +94,7 @@ In other words, this command does the snapshot to trie conversion.
9394
Usage: "Check that there is no 'dangling' snap storage",
9495
ArgsUsage: "<root>",
9596
Action: checkDanglingStorage,
96-
Flags: utils.GroupFlags(utils.NetworkFlags, utils.DatabasePathFlags),
97+
Flags: flags.Merge(utils.NetworkFlags, utils.DatabasePathFlags),
9798
Description: `
9899
geth snapshot check-dangling-storage <state-root> traverses the snap storage
99100
data, and verifies that all snapshot storage data has a corresponding account.
@@ -104,7 +105,7 @@ data, and verifies that all snapshot storage data has a corresponding account.
104105
Usage: "Check all snapshot layers for the a specific account",
105106
ArgsUsage: "<address | hash>",
106107
Action: checkAccount,
107-
Flags: utils.GroupFlags(utils.NetworkFlags, utils.DatabasePathFlags),
108+
Flags: flags.Merge(utils.NetworkFlags, utils.DatabasePathFlags),
108109
Description: `
109110
geth snapshot inspect-account <address | hash> checks all snapshot layers and prints out
110111
information about the specified address.
@@ -115,7 +116,7 @@ information about the specified address.
115116
Usage: "Traverse the state with given root hash and perform quick verification",
116117
ArgsUsage: "<root>",
117118
Action: traverseState,
118-
Flags: utils.GroupFlags(utils.NetworkFlags, utils.DatabasePathFlags),
119+
Flags: flags.Merge(utils.NetworkFlags, utils.DatabasePathFlags),
119120
Description: `
120121
geth snapshot traverse-state <state-root>
121122
will traverse the whole state from the given state root and will abort if any
@@ -130,7 +131,7 @@ It's also usable without snapshot enabled.
130131
Usage: "Traverse the state with given root hash and perform detailed verification",
131132
ArgsUsage: "<root>",
132133
Action: traverseRawState,
133-
Flags: utils.GroupFlags(utils.NetworkFlags, utils.DatabasePathFlags),
134+
Flags: flags.Merge(utils.NetworkFlags, utils.DatabasePathFlags),
134135
Description: `
135136
geth snapshot traverse-rawstate <state-root>
136137
will traverse the whole state from the given root and will abort if any referenced
@@ -146,7 +147,7 @@ It's also usable without snapshot enabled.
146147
Usage: "Dump a specific block from storage (same as 'geth dump' but using snapshots)",
147148
ArgsUsage: "[? <blockHash> | <blockNum>]",
148149
Action: dumpState,
149-
Flags: utils.GroupFlags([]cli.Flag{
150+
Flags: flags.Merge([]cli.Flag{
150151
utils.ExcludeCodeFlag,
151152
utils.ExcludeStorageFlag,
152153
utils.StartKeyFlag,

cmd/utils/flags.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -994,15 +994,6 @@ var (
994994
}
995995
)
996996

997-
// GroupFlags combines the given flag slices together and returns the merged one.
998-
func GroupFlags(groups ...[]cli.Flag) []cli.Flag {
999-
var ret []cli.Flag
1000-
for _, group := range groups {
1001-
ret = append(ret, group...)
1002-
}
1003-
return ret
1004-
}
1005-
1006997
// MakeDataDir retrieves the currently requested data directory, terminating
1007998
// if none (or the empty string) is specified. If the node is starting a testnet,
1008999
// then a subdirectory of the specified datadir will be used.

0 commit comments

Comments
 (0)