github.com/cryptotooltop/go-ethereum@v0.0.0-20231103184714-151d1922f3e5/cmd/geth/usage.go (about)

     1  // Copyright 2015 The go-ethereum Authors
     2  // This file is part of go-ethereum.
     3  //
     4  // go-ethereum is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // go-ethereum is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU General Public License
    15  // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  // Contains the geth command usage template and generator.
    18  
    19  package main
    20  
    21  import (
    22  	"io"
    23  	"sort"
    24  
    25  	"gopkg.in/urfave/cli.v1"
    26  
    27  	"github.com/scroll-tech/go-ethereum/cmd/utils"
    28  	"github.com/scroll-tech/go-ethereum/internal/debug"
    29  	"github.com/scroll-tech/go-ethereum/internal/flags"
    30  )
    31  
    32  // AppHelpFlagGroups is the application flags, grouped by functionality.
    33  var AppHelpFlagGroups = []flags.FlagGroup{
    34  	{
    35  		Name: "ETHEREUM",
    36  		Flags: []cli.Flag{
    37  			configFileFlag,
    38  			utils.DataDirFlag,
    39  			utils.AncientFlag,
    40  			utils.MinFreeDiskSpaceFlag,
    41  			utils.KeyStoreDirFlag,
    42  			utils.USBFlag,
    43  			utils.SmartCardDaemonPathFlag,
    44  			utils.NetworkIdFlag,
    45  			utils.MainnetFlag,
    46  			utils.GoerliFlag,
    47  			utils.RinkebyFlag,
    48  			utils.RopstenFlag,
    49  			utils.SepoliaFlag,
    50  			utils.ScrollAlphaFlag,
    51  			utils.ScrollSepoliaFlag,
    52  			utils.ScrollFlag,
    53  			utils.SyncModeFlag,
    54  			utils.ExitWhenSyncedFlag,
    55  			utils.GCModeFlag,
    56  			utils.TxLookupLimitFlag,
    57  			utils.EthStatsURLFlag,
    58  			utils.IdentityFlag,
    59  			utils.LightKDFFlag,
    60  			utils.WhitelistFlag,
    61  		},
    62  	},
    63  	{
    64  		Name: "LIGHT CLIENT",
    65  		Flags: []cli.Flag{
    66  			utils.LightServeFlag,
    67  			utils.LightIngressFlag,
    68  			utils.LightEgressFlag,
    69  			utils.LightMaxPeersFlag,
    70  			utils.UltraLightServersFlag,
    71  			utils.UltraLightFractionFlag,
    72  			utils.UltraLightOnlyAnnounceFlag,
    73  			utils.LightNoPruneFlag,
    74  			utils.LightNoSyncServeFlag,
    75  		},
    76  	},
    77  	{
    78  		Name: "DEVELOPER CHAIN",
    79  		Flags: []cli.Flag{
    80  			utils.DeveloperFlag,
    81  			utils.DeveloperPeriodFlag,
    82  			utils.DeveloperGasLimitFlag,
    83  		},
    84  	},
    85  	{
    86  		Name: "ETHASH",
    87  		Flags: []cli.Flag{
    88  			utils.EthashCacheDirFlag,
    89  			utils.EthashCachesInMemoryFlag,
    90  			utils.EthashCachesOnDiskFlag,
    91  			utils.EthashCachesLockMmapFlag,
    92  			utils.EthashDatasetDirFlag,
    93  			utils.EthashDatasetsInMemoryFlag,
    94  			utils.EthashDatasetsOnDiskFlag,
    95  			utils.EthashDatasetsLockMmapFlag,
    96  		},
    97  	},
    98  	{
    99  		Name: "TRANSACTION POOL",
   100  		Flags: []cli.Flag{
   101  			utils.TxPoolLocalsFlag,
   102  			utils.TxPoolNoLocalsFlag,
   103  			utils.TxPoolJournalFlag,
   104  			utils.TxPoolRejournalFlag,
   105  			utils.TxPoolPriceLimitFlag,
   106  			utils.TxPoolPriceBumpFlag,
   107  			utils.TxPoolAccountSlotsFlag,
   108  			utils.TxPoolGlobalSlotsFlag,
   109  			utils.TxPoolAccountQueueFlag,
   110  			utils.TxPoolGlobalQueueFlag,
   111  			utils.TxPoolLifetimeFlag,
   112  		},
   113  	},
   114  	{
   115  		Name: "PERFORMANCE TUNING",
   116  		Flags: []cli.Flag{
   117  			utils.CacheFlag,
   118  			utils.CacheDatabaseFlag,
   119  			utils.CacheTrieFlag,
   120  			utils.CacheTrieJournalFlag,
   121  			utils.CacheTrieRejournalFlag,
   122  			utils.CacheGCFlag,
   123  			utils.CacheSnapshotFlag,
   124  			utils.CacheNoPrefetchFlag,
   125  			utils.CachePreimagesFlag,
   126  		},
   127  	},
   128  	{
   129  		Name: "ACCOUNT",
   130  		Flags: []cli.Flag{
   131  			utils.UnlockedAccountFlag,
   132  			utils.PasswordFileFlag,
   133  			utils.ExternalSignerFlag,
   134  			utils.InsecureUnlockAllowedFlag,
   135  		},
   136  	},
   137  	{
   138  		Name: "API AND CONSOLE",
   139  		Flags: []cli.Flag{
   140  			utils.IPCDisabledFlag,
   141  			utils.IPCPathFlag,
   142  			utils.HTTPEnabledFlag,
   143  			utils.HTTPListenAddrFlag,
   144  			utils.HTTPPortFlag,
   145  			utils.HTTPApiFlag,
   146  			utils.HTTPPathPrefixFlag,
   147  			utils.HTTPCORSDomainFlag,
   148  			utils.HTTPVirtualHostsFlag,
   149  			utils.WSEnabledFlag,
   150  			utils.WSListenAddrFlag,
   151  			utils.WSPortFlag,
   152  			utils.WSApiFlag,
   153  			utils.WSPathPrefixFlag,
   154  			utils.WSAllowedOriginsFlag,
   155  			utils.GraphQLEnabledFlag,
   156  			utils.GraphQLCORSDomainFlag,
   157  			utils.GraphQLVirtualHostsFlag,
   158  			utils.RPCGlobalGasCapFlag,
   159  			utils.RPCGlobalEVMTimeoutFlag,
   160  			utils.RPCGlobalTxFeeCapFlag,
   161  			utils.AllowUnprotectedTxs,
   162  			utils.JSpathFlag,
   163  			utils.ExecFlag,
   164  			utils.PreloadJSFlag,
   165  		},
   166  	},
   167  	{
   168  		Name: "NETWORKING",
   169  		Flags: []cli.Flag{
   170  			utils.BootnodesFlag,
   171  			utils.DNSDiscoveryFlag,
   172  			utils.ListenPortFlag,
   173  			utils.MaxPeersFlag,
   174  			utils.MaxPendingPeersFlag,
   175  			utils.NATFlag,
   176  			utils.NoDiscoverFlag,
   177  			utils.DiscoveryV5Flag,
   178  			utils.NetrestrictFlag,
   179  			utils.NodeKeyFileFlag,
   180  			utils.NodeKeyHexFlag,
   181  		},
   182  	},
   183  	{
   184  		Name: "MINER",
   185  		Flags: []cli.Flag{
   186  			utils.MiningEnabledFlag,
   187  			utils.MinerThreadsFlag,
   188  			utils.MinerNotifyFlag,
   189  			utils.MinerNotifyFullFlag,
   190  			utils.MinerGasPriceFlag,
   191  			utils.MinerGasLimitFlag,
   192  			utils.MinerEtherbaseFlag,
   193  			utils.MinerExtraDataFlag,
   194  			utils.MinerRecommitIntervalFlag,
   195  			utils.MinerNoVerifyFlag,
   196  			utils.MinerStoreSkippedTxTracesFlag,
   197  		},
   198  	},
   199  	{
   200  		Name: "GAS PRICE ORACLE",
   201  		Flags: []cli.Flag{
   202  			utils.GpoBlocksFlag,
   203  			utils.GpoPercentileFlag,
   204  			utils.GpoMaxGasPriceFlag,
   205  			utils.GpoIgnoreGasPriceFlag,
   206  		},
   207  	},
   208  	{
   209  		Name: "VIRTUAL MACHINE",
   210  		Flags: []cli.Flag{
   211  			utils.VMEnableDebugFlag,
   212  		},
   213  	},
   214  	{
   215  		Name: "LOGGING AND DEBUGGING",
   216  		Flags: append([]cli.Flag{
   217  			utils.FakePoWFlag,
   218  			utils.NoCompactionFlag,
   219  		}, debug.Flags...),
   220  	},
   221  	{
   222  		Name:  "METRICS AND STATS",
   223  		Flags: metricsFlags,
   224  	},
   225  	{
   226  		Name: "ALIASED (deprecated)",
   227  		Flags: []cli.Flag{
   228  			utils.NoUSBFlag,
   229  		},
   230  	},
   231  	{
   232  		Name: "MISC",
   233  		Flags: []cli.Flag{
   234  			utils.SnapshotFlag,
   235  			utils.BloomFilterSizeFlag,
   236  			cli.HelpFlag,
   237  			utils.CatalystFlag,
   238  		},
   239  	},
   240  }
   241  
   242  func init() {
   243  	// Override the default app help template
   244  	cli.AppHelpTemplate = flags.AppHelpTemplate
   245  
   246  	// Override the default app help printer, but only for the global app help
   247  	originalHelpPrinter := cli.HelpPrinter
   248  	cli.HelpPrinter = func(w io.Writer, tmpl string, data interface{}) {
   249  		if tmpl == flags.AppHelpTemplate {
   250  			// Iterate over all the flags and add any uncategorized ones
   251  			categorized := make(map[string]struct{})
   252  			for _, group := range AppHelpFlagGroups {
   253  				for _, flag := range group.Flags {
   254  					categorized[flag.String()] = struct{}{}
   255  				}
   256  			}
   257  			deprecated := make(map[string]struct{})
   258  			for _, flag := range utils.DeprecatedFlags {
   259  				deprecated[flag.String()] = struct{}{}
   260  			}
   261  			// Only add uncategorized flags if they are not deprecated
   262  			var uncategorized []cli.Flag
   263  			for _, flag := range data.(*cli.App).Flags {
   264  				if _, ok := categorized[flag.String()]; !ok {
   265  					if _, ok := deprecated[flag.String()]; !ok {
   266  						uncategorized = append(uncategorized, flag)
   267  					}
   268  				}
   269  			}
   270  			if len(uncategorized) > 0 {
   271  				// Append all ungategorized options to the misc group
   272  				miscs := len(AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags)
   273  				AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags = append(AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags, uncategorized...)
   274  
   275  				// Make sure they are removed afterwards
   276  				defer func() {
   277  					AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags = AppHelpFlagGroups[len(AppHelpFlagGroups)-1].Flags[:miscs]
   278  				}()
   279  			}
   280  			// Render out custom usage screen
   281  			originalHelpPrinter(w, tmpl, flags.HelpData{App: data, FlagGroups: AppHelpFlagGroups})
   282  		} else if tmpl == flags.CommandHelpTemplate {
   283  			// Iterate over all command specific flags and categorize them
   284  			categorized := make(map[string][]cli.Flag)
   285  			for _, flag := range data.(cli.Command).Flags {
   286  				if _, ok := categorized[flag.String()]; !ok {
   287  					categorized[flags.FlagCategory(flag, AppHelpFlagGroups)] = append(categorized[flags.FlagCategory(flag, AppHelpFlagGroups)], flag)
   288  				}
   289  			}
   290  
   291  			// sort to get a stable ordering
   292  			sorted := make([]flags.FlagGroup, 0, len(categorized))
   293  			for cat, flgs := range categorized {
   294  				sorted = append(sorted, flags.FlagGroup{Name: cat, Flags: flgs})
   295  			}
   296  			sort.Sort(flags.ByCategory(sorted))
   297  
   298  			// add sorted array to data and render with default printer
   299  			originalHelpPrinter(w, tmpl, map[string]interface{}{
   300  				"cmd":              data,
   301  				"categorizedFlags": sorted,
   302  			})
   303  		} else {
   304  			originalHelpPrinter(w, tmpl, data)
   305  		}
   306  	}
   307  }