Skip to content

Commit 5fff93d

Browse files
committed
cmd: group network and database flags together
1 parent f3d100e commit 5fff93d

File tree

4 files changed

+46
-74
lines changed

4 files changed

+46
-74
lines changed

cmd/XDC/chaincmd.go

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"os"
2323
"runtime"
24+
"slices"
2425
"strconv"
2526
"sync/atomic"
2627
"time"
@@ -41,13 +42,7 @@ var (
4142
Name: "init",
4243
Usage: "Bootstrap and initialize a new genesis block",
4344
ArgsUsage: "<genesisPath>",
44-
Flags: []cli.Flag{
45-
utils.DataDirFlag,
46-
utils.XDCXDataDirFlag,
47-
utils.MainnetFlag,
48-
utils.TestnetFlag,
49-
utils.DevnetFlag,
50-
},
45+
Flags: slices.Concat(utils.NetworkFlags, utils.DatabaseFlags),
5146
Description: `
5247
The init command initializes a new genesis block and definition for the network.
5348
This is a destructive action and changes the network in which you will be
@@ -60,9 +55,7 @@ It expects the genesis file or the network name [ mainnet | testnet | devnet ] a
6055
Name: "import",
6156
Usage: "Import a blockchain file",
6257
ArgsUsage: "<filename> (<filename 2> ... <filename N>) ",
63-
Flags: []cli.Flag{
64-
utils.DataDirFlag,
65-
utils.XDCXDataDirFlag,
58+
Flags: slices.Concat([]cli.Flag{
6659
utils.CacheFlag,
6760
utils.SyncModeFlag,
6861
utils.GCModeFlag,
@@ -80,7 +73,7 @@ It expects the genesis file or the network name [ mainnet | testnet | devnet ] a
8073
utils.MetricsInfluxDBTokenFlag,
8174
utils.MetricsInfluxDBBucketFlag,
8275
utils.MetricsInfluxDBOrganizationFlag,
83-
},
76+
}, utils.DatabaseFlags),
8477
Description: `
8578
The import command imports blocks from an RLP-encoded form. The form can be one file
8679
with several RLP-encoded blocks, or several files can be used.
@@ -93,12 +86,10 @@ processing will proceed even if an individual RLP-file import failure occurs.`,
9386
Name: "export",
9487
Usage: "Export blockchain into file",
9588
ArgsUsage: "<filename> [<blockNumFirst> <blockNumLast>]",
96-
Flags: []cli.Flag{
97-
utils.DataDirFlag,
98-
utils.XDCXDataDirFlag,
89+
Flags: slices.Concat([]cli.Flag{
9990
utils.CacheFlag,
10091
utils.SyncModeFlag,
101-
},
92+
}, utils.DatabaseFlags),
10293
Description: `
10394
Requires a first argument of the file to write to.
10495
Optional second and third arguments control the first and
@@ -110,12 +101,10 @@ if already existing.`,
110101
Name: "import-preimages",
111102
Usage: "Import the preimage database from an RLP stream",
112103
ArgsUsage: "<datafile>",
113-
Flags: []cli.Flag{
114-
utils.DataDirFlag,
115-
utils.XDCXDataDirFlag,
104+
Flags: slices.Concat([]cli.Flag{
116105
utils.CacheFlag,
117106
utils.SyncModeFlag,
118-
},
107+
}, utils.DatabaseFlags),
119108
Category: "BLOCKCHAIN COMMANDS",
120109
Description: `
121110
The import-preimages command imports hash preimages from an RLP encoded stream.`,
@@ -125,12 +114,10 @@ if already existing.`,
125114
Name: "export-preimages",
126115
Usage: "Export the preimage database into an RLP stream",
127116
ArgsUsage: "<dumpfile>",
128-
Flags: []cli.Flag{
129-
utils.DataDirFlag,
130-
utils.XDCXDataDirFlag,
117+
Flags: slices.Concat([]cli.Flag{
131118
utils.CacheFlag,
132119
utils.SyncModeFlag,
133-
},
120+
}, utils.DatabaseFlags),
134121
Description: `
135122
The export-preimages command export hash preimages to an RLP encoded stream`,
136123
}
@@ -139,12 +126,10 @@ The export-preimages command export hash preimages to an RLP encoded stream`,
139126
Name: "dump",
140127
Usage: "Dump a specific block from storage",
141128
ArgsUsage: "[<blockHash> | <blockNum>]...",
142-
Flags: []cli.Flag{
143-
utils.DataDirFlag,
144-
utils.XDCXDataDirFlag,
129+
Flags: slices.Concat([]cli.Flag{
145130
utils.CacheFlag,
146131
utils.SyncModeFlag,
147-
},
132+
}, utils.DatabaseFlags),
148133
Category: "BLOCKCHAIN COMMANDS",
149134
Description: `
150135
The arguments are interpreted as block numbers or hashes.

cmd/XDC/dbcmd.go

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"os"
2222
"path/filepath"
23+
"slices"
2324
"time"
2425

2526
"github.com/XinFinOrg/XDPoSChain/cmd/utils"
@@ -38,9 +39,7 @@ var (
3839
Name: "removedb",
3940
Usage: "Remove blockchain and state databases",
4041
ArgsUsage: " ",
41-
Flags: []cli.Flag{
42-
utils.DataDirFlag,
43-
},
42+
Flags: utils.DatabaseFlags,
4443
Description: `
4544
Remove blockchain and state databases`,
4645
}
@@ -61,41 +60,29 @@ Remove blockchain and state databases`,
6160
Action: inspect,
6261
Name: "inspect",
6362
ArgsUsage: "<prefix> <start>",
64-
Flags: []cli.Flag{
65-
utils.DataDirFlag,
63+
Flags: slices.Concat([]cli.Flag{
6664
utils.SyncModeFlag,
67-
utils.MainnetFlag,
68-
utils.TestnetFlag,
69-
utils.DevnetFlag,
70-
},
65+
}, utils.NetworkFlags, utils.DatabaseFlags),
7166
Usage: "Inspect the storage size for each type of data in the database",
7267
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.`,
7368
}
7469
dbStatCmd = &cli.Command{
7570
Action: dbStats,
7671
Name: "stats",
7772
Usage: "Print leveldb statistics",
78-
Flags: []cli.Flag{
79-
utils.DataDirFlag,
73+
Flags: slices.Concat([]cli.Flag{
8074
utils.SyncModeFlag,
81-
utils.MainnetFlag,
82-
utils.TestnetFlag,
83-
utils.DevnetFlag,
84-
},
75+
}, utils.NetworkFlags, utils.DatabaseFlags),
8576
}
8677
dbCompactCmd = &cli.Command{
8778
Action: dbCompact,
8879
Name: "compact",
8980
Usage: "Compact leveldb database. WARNING: May take a very long time",
90-
Flags: []cli.Flag{
91-
utils.DataDirFlag,
81+
Flags: slices.Concat([]cli.Flag{
9282
utils.SyncModeFlag,
93-
utils.MainnetFlag,
94-
utils.TestnetFlag,
95-
utils.DevnetFlag,
9683
utils.CacheFlag,
9784
utils.CacheDatabaseFlag,
98-
},
85+
}, utils.NetworkFlags, utils.DatabaseFlags),
9986
Description: `This command performs a database compaction.
10087
WARNING: This operation may take a very long time to finish, and may cause database
10188
corruption if it is aborted during execution'!`,
@@ -105,27 +92,19 @@ corruption if it is aborted during execution'!`,
10592
Name: "get",
10693
Usage: "Show the value of a database key",
10794
ArgsUsage: "<hex-encoded key>",
108-
Flags: []cli.Flag{
109-
utils.DataDirFlag,
95+
Flags: slices.Concat([]cli.Flag{
11096
utils.SyncModeFlag,
111-
utils.MainnetFlag,
112-
utils.TestnetFlag,
113-
utils.DevnetFlag,
114-
},
97+
}, utils.NetworkFlags, utils.DatabaseFlags),
11598
Description: "This command looks up the specified database key from the database.",
11699
}
117100
dbDeleteCmd = &cli.Command{
118101
Action: dbDelete,
119102
Name: "delete",
120103
Usage: "Delete a database key (WARNING: may corrupt your database)",
121104
ArgsUsage: "<hex-encoded key>",
122-
Flags: []cli.Flag{
123-
utils.DataDirFlag,
105+
Flags: slices.Concat([]cli.Flag{
124106
utils.SyncModeFlag,
125-
utils.MainnetFlag,
126-
utils.TestnetFlag,
127-
utils.DevnetFlag,
128-
},
107+
}, utils.NetworkFlags, utils.DatabaseFlags),
129108
Description: `This command deletes the specified database key from the database.
130109
WARNING: This is a low-level operation which may cause database corruption!`,
131110
}
@@ -134,13 +113,9 @@ WARNING: This is a low-level operation which may cause database corruption!`,
134113
Name: "put",
135114
Usage: "Set the value of a database key (WARNING: may corrupt your database)",
136115
ArgsUsage: "<hex-encoded key> <hex-encoded value>",
137-
Flags: []cli.Flag{
138-
utils.DataDirFlag,
116+
Flags: slices.Concat([]cli.Flag{
139117
utils.SyncModeFlag,
140-
utils.MainnetFlag,
141-
utils.TestnetFlag,
142-
utils.DevnetFlag,
143-
},
118+
}, utils.NetworkFlags, utils.DatabaseFlags),
144119
Description: `This command sets a given database key to the given value.
145120
WARNING: This is a low-level operation which may cause database corruption!`,
146121
}

cmd/XDC/main.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"os"
2222
"runtime"
23+
"slices"
2324
"sort"
2425
"strings"
2526
"time"
@@ -52,15 +53,15 @@ var (
5253
gitCommit = ""
5354
// The app that holds all commands and flags.
5455
app = flags.NewApp(gitCommit, "the XDPoSChain command line interface")
55-
// flags that configure the node
56-
nodeFlags = []cli.Flag{
56+
57+
// The app that holds all commands and flags.
58+
nodeFlags = slices.Concat([]cli.Flag{
5759
utils.IdentityFlag,
5860
utils.UnlockedAccountFlag,
5961
utils.PasswordFileFlag,
6062
utils.BootnodesFlag,
6163
utils.BootnodesV4Flag,
6264
utils.BootnodesV5Flag,
63-
utils.DataDirFlag,
6465
utils.KeyStoreDirFlag,
6566
utils.NoUSBFlag, // deprecated
6667
utils.USBFlag,
@@ -72,7 +73,6 @@ var (
7273
//utils.EthashDatasetsInMemoryFlag,
7374
//utils.EthashDatasetsOnDiskFlag,
7475
utils.XDCXEnabledFlag,
75-
utils.XDCXDataDirFlag,
7676
utils.XDCXDBEngineFlag,
7777
utils.XDCXDBConnectionUrlFlag,
7878
utils.XDCXDBReplicaSetNameFlag,
@@ -115,9 +115,6 @@ var (
115115
utils.NodeKeyHexFlag,
116116
//utils.DeveloperFlag,
117117
//utils.DeveloperPeriodFlag,
118-
utils.MainnetFlag,
119-
utils.TestnetFlag,
120-
utils.DevnetFlag,
121118
//utils.VMEnableDebugFlag,
122119
utils.Enable0xPrefixFlag,
123120
utils.EnableXDCPrefixFlag,
@@ -139,7 +136,7 @@ var (
139136
utils.StoreRewardFlag,
140137
utils.SetHeadFlag,
141138
utils.XDCSlaveModeFlag,
142-
}
139+
}, utils.NetworkFlags, utils.DatabaseFlags)
143140

144141
rpcFlags = []cli.Flag{
145142
utils.HTTPEnabledFlag,

cmd/utils/flags.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,21 @@ var (
788788
}
789789
)
790790

791+
var (
792+
// NetworkFlags is the flag group of all built-in supported networks.
793+
NetworkFlags = []cli.Flag{
794+
MainnetFlag,
795+
TestnetFlag,
796+
DevnetFlag,
797+
}
798+
799+
// DatabaseFlags is the flag group of all database flags.
800+
DatabaseFlags = []cli.Flag{
801+
DataDirFlag,
802+
XDCXDataDirFlag,
803+
}
804+
)
805+
791806
// MakeDataDir retrieves the currently requested data directory, terminating
792807
// if none (or the empty string) is specified. If the node is starting a testnet,
793808
// the a subdirectory of the specified datadir will be used.

0 commit comments

Comments
 (0)