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