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