Merge pull request #921 from gzliudan/group-net-db-flags

cmd: group network and database flags together
This commit is contained in:
Daniel Liu 2025-03-20 14:07:11 +08:00 committed by GitHub
commit b7eeb0d939
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 46 additions and 74 deletions

View file

@ -21,6 +21,7 @@ import (
"fmt"
"os"
"runtime"
"slices"
"strconv"
"sync/atomic"
"time"
@ -41,13 +42,7 @@ var (
Name: "init",
Usage: "Bootstrap and initialize a new genesis block",
ArgsUsage: "<genesisPath>",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.XDCXDataDirFlag,
utils.MainnetFlag,
utils.TestnetFlag,
utils.DevnetFlag,
},
Flags: slices.Concat(utils.NetworkFlags, utils.DatabaseFlags),
Description: `
The init command initializes a new genesis block and definition for the network.
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
Name: "import",
Usage: "Import a blockchain file",
ArgsUsage: "<filename> (<filename 2> ... <filename N>) ",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.XDCXDataDirFlag,
Flags: slices.Concat([]cli.Flag{
utils.CacheFlag,
utils.SyncModeFlag,
utils.GCModeFlag,
@ -80,7 +73,7 @@ It expects the genesis file or the network name [ mainnet | testnet | devnet ] a
utils.MetricsInfluxDBTokenFlag,
utils.MetricsInfluxDBBucketFlag,
utils.MetricsInfluxDBOrganizationFlag,
},
}, utils.DatabaseFlags),
Description: `
The import command imports blocks from an RLP-encoded form. The form can be one file
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.`,
Name: "export",
Usage: "Export blockchain into file",
ArgsUsage: "<filename> [<blockNumFirst> <blockNumLast>]",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.XDCXDataDirFlag,
Flags: slices.Concat([]cli.Flag{
utils.CacheFlag,
utils.SyncModeFlag,
},
}, utils.DatabaseFlags),
Description: `
Requires a first argument of the file to write to.
Optional second and third arguments control the first and
@ -110,12 +101,10 @@ if already existing.`,
Name: "import-preimages",
Usage: "Import the preimage database from an RLP stream",
ArgsUsage: "<datafile>",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.XDCXDataDirFlag,
Flags: slices.Concat([]cli.Flag{
utils.CacheFlag,
utils.SyncModeFlag,
},
}, utils.DatabaseFlags),
Category: "BLOCKCHAIN COMMANDS",
Description: `
The import-preimages command imports hash preimages from an RLP encoded stream.`,
@ -125,12 +114,10 @@ if already existing.`,
Name: "export-preimages",
Usage: "Export the preimage database into an RLP stream",
ArgsUsage: "<dumpfile>",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.XDCXDataDirFlag,
Flags: slices.Concat([]cli.Flag{
utils.CacheFlag,
utils.SyncModeFlag,
},
}, utils.DatabaseFlags),
Description: `
The export-preimages command export hash preimages to an RLP encoded stream`,
}
@ -139,12 +126,10 @@ The export-preimages command export hash preimages to an RLP encoded stream`,
Name: "dump",
Usage: "Dump a specific block from storage",
ArgsUsage: "[<blockHash> | <blockNum>]...",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.XDCXDataDirFlag,
Flags: slices.Concat([]cli.Flag{
utils.CacheFlag,
utils.SyncModeFlag,
},
}, utils.DatabaseFlags),
Category: "BLOCKCHAIN COMMANDS",
Description: `
The arguments are interpreted as block numbers or hashes.

View file

@ -20,6 +20,7 @@ import (
"fmt"
"os"
"path/filepath"
"slices"
"time"
"github.com/XinFinOrg/XDPoSChain/cmd/utils"
@ -38,9 +39,7 @@ var (
Name: "removedb",
Usage: "Remove blockchain and state databases",
ArgsUsage: " ",
Flags: []cli.Flag{
utils.DataDirFlag,
},
Flags: utils.DatabaseFlags,
Description: `
Remove blockchain and state databases`,
}
@ -61,13 +60,9 @@ Remove blockchain and state databases`,
Action: inspect,
Name: "inspect",
ArgsUsage: "<prefix> <start>",
Flags: []cli.Flag{
utils.DataDirFlag,
Flags: slices.Concat([]cli.Flag{
utils.SyncModeFlag,
utils.MainnetFlag,
utils.TestnetFlag,
utils.DevnetFlag,
},
}, utils.NetworkFlags, utils.DatabaseFlags),
Usage: "Inspect the storage size for each type of data in the database",
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.`,
}
@ -75,27 +70,19 @@ Remove blockchain and state databases`,
Action: dbStats,
Name: "stats",
Usage: "Print leveldb statistics",
Flags: []cli.Flag{
utils.DataDirFlag,
Flags: slices.Concat([]cli.Flag{
utils.SyncModeFlag,
utils.MainnetFlag,
utils.TestnetFlag,
utils.DevnetFlag,
},
}, utils.NetworkFlags, utils.DatabaseFlags),
}
dbCompactCmd = &cli.Command{
Action: dbCompact,
Name: "compact",
Usage: "Compact leveldb database. WARNING: May take a very long time",
Flags: []cli.Flag{
utils.DataDirFlag,
Flags: slices.Concat([]cli.Flag{
utils.SyncModeFlag,
utils.MainnetFlag,
utils.TestnetFlag,
utils.DevnetFlag,
utils.CacheFlag,
utils.CacheDatabaseFlag,
},
}, utils.NetworkFlags, utils.DatabaseFlags),
Description: `This command performs a database compaction.
WARNING: This operation may take a very long time to finish, and may cause database
corruption if it is aborted during execution'!`,
@ -105,13 +92,9 @@ corruption if it is aborted during execution'!`,
Name: "get",
Usage: "Show the value of a database key",
ArgsUsage: "<hex-encoded key>",
Flags: []cli.Flag{
utils.DataDirFlag,
Flags: slices.Concat([]cli.Flag{
utils.SyncModeFlag,
utils.MainnetFlag,
utils.TestnetFlag,
utils.DevnetFlag,
},
}, utils.NetworkFlags, utils.DatabaseFlags),
Description: "This command looks up the specified database key from the database.",
}
dbDeleteCmd = &cli.Command{
@ -119,13 +102,9 @@ corruption if it is aborted during execution'!`,
Name: "delete",
Usage: "Delete a database key (WARNING: may corrupt your database)",
ArgsUsage: "<hex-encoded key>",
Flags: []cli.Flag{
utils.DataDirFlag,
Flags: slices.Concat([]cli.Flag{
utils.SyncModeFlag,
utils.MainnetFlag,
utils.TestnetFlag,
utils.DevnetFlag,
},
}, utils.NetworkFlags, utils.DatabaseFlags),
Description: `This command deletes the specified database key from the database.
WARNING: This is a low-level operation which may cause database corruption!`,
}
@ -134,13 +113,9 @@ WARNING: This is a low-level operation which may cause database corruption!`,
Name: "put",
Usage: "Set the value of a database key (WARNING: may corrupt your database)",
ArgsUsage: "<hex-encoded key> <hex-encoded value>",
Flags: []cli.Flag{
utils.DataDirFlag,
Flags: slices.Concat([]cli.Flag{
utils.SyncModeFlag,
utils.MainnetFlag,
utils.TestnetFlag,
utils.DevnetFlag,
},
}, utils.NetworkFlags, utils.DatabaseFlags),
Description: `This command sets a given database key to the given value.
WARNING: This is a low-level operation which may cause database corruption!`,
}

View file

@ -20,6 +20,7 @@ import (
"fmt"
"os"
"runtime"
"slices"
"sort"
"strings"
"time"
@ -52,15 +53,15 @@ var (
gitCommit = ""
// The app that holds all commands and flags.
app = flags.NewApp(gitCommit, "the XDPoSChain command line interface")
// flags that configure the node
nodeFlags = []cli.Flag{
// The app that holds all commands and flags.
nodeFlags = slices.Concat([]cli.Flag{
utils.IdentityFlag,
utils.UnlockedAccountFlag,
utils.PasswordFileFlag,
utils.BootnodesFlag,
utils.BootnodesV4Flag,
utils.BootnodesV5Flag,
utils.DataDirFlag,
utils.KeyStoreDirFlag,
utils.NoUSBFlag, // deprecated
utils.USBFlag,
@ -72,7 +73,6 @@ var (
//utils.EthashDatasetsInMemoryFlag,
//utils.EthashDatasetsOnDiskFlag,
utils.XDCXEnabledFlag,
utils.XDCXDataDirFlag,
utils.XDCXDBEngineFlag,
utils.XDCXDBConnectionUrlFlag,
utils.XDCXDBReplicaSetNameFlag,
@ -115,9 +115,6 @@ var (
utils.NodeKeyHexFlag,
//utils.DeveloperFlag,
//utils.DeveloperPeriodFlag,
utils.MainnetFlag,
utils.TestnetFlag,
utils.DevnetFlag,
//utils.VMEnableDebugFlag,
utils.Enable0xPrefixFlag,
utils.EnableXDCPrefixFlag,
@ -139,7 +136,7 @@ var (
utils.StoreRewardFlag,
utils.SetHeadFlag,
utils.XDCSlaveModeFlag,
}
}, utils.NetworkFlags, utils.DatabaseFlags)
rpcFlags = []cli.Flag{
utils.HTTPEnabledFlag,

View file

@ -788,6 +788,21 @@ var (
}
)
var (
// NetworkFlags is the flag group of all built-in supported networks.
NetworkFlags = []cli.Flag{
MainnetFlag,
TestnetFlag,
DevnetFlag,
}
// DatabaseFlags is the flag group of all database flags.
DatabaseFlags = []cli.Flag{
DataDirFlag,
XDCXDataDirFlag,
}
)
// MakeDataDir retrieves the currently requested data directory, terminating
// if none (or the empty string) is specified. If the node is starting a testnet,
// the a subdirectory of the specified datadir will be used.