gitee.com/liu-zhao234568/cntest@v1.0.0/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  	"gitee.com/liu-zhao234568/cntest/cmd/utils"
    26  	"gitee.com/liu-zhao234568/cntest/internal/debug"
    27  	"gitee.com/liu-zhao234568/cntest/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.CalaverasFlag,
    48  			utils.RopstenFlag,
    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  		},
    79  	},
    80  	{
    81  		Name: "ETHASH",
    82  		Flags: []cli.Flag{
    83  			utils.EthashCacheDirFlag,
    84  			utils.EthashCachesInMemoryFlag,
    85  			utils.EthashCachesOnDiskFlag,
    86  			utils.EthashCachesLockMmapFlag,
    87  			utils.EthashDatasetDirFlag,
    88  			utils.EthashDatasetsInMemoryFlag,
    89  			utils.EthashDatasetsOnDiskFlag,
    90  			utils.EthashDatasetsLockMmapFlag,
    91  		},
    92  	},
    93  	{
    94  		Name: "TRANSACTION POOL",
    95  		Flags: []cli.Flag{
    96  			utils.TxPoolLocalsFlag,
    97  			utils.TxPoolNoLocalsFlag,
    98  			utils.TxPoolJournalFlag,
    99  			utils.TxPoolRejournalFlag,
   100  			utils.TxPoolPriceLimitFlag,
   101  			utils.TxPoolPriceBumpFlag,
   102  			utils.TxPoolAccountSlotsFlag,
   103  			utils.TxPoolGlobalSlotsFlag,
   104  			utils.TxPoolAccountQueueFlag,
   105  			utils.TxPoolGlobalQueueFlag,
   106  			utils.TxPoolLifetimeFlag,
   107  		},
   108  	},
   109  	{
   110  		Name: "PERFORMANCE TUNING",
   111  		Flags: []cli.Flag{
   112  			utils.CacheFlag,
   113  			utils.CacheDatabaseFlag,
   114  			utils.CacheTrieFlag,
   115  			utils.CacheTrieJournalFlag,
   116  			utils.CacheTrieRejournalFlag,
   117  			utils.CacheGCFlag,
   118  			utils.CacheSnapshotFlag,
   119  			utils.CacheNoPrefetchFlag,
   120  			utils.CachePreimagesFlag,
   121  		},
   122  	},
   123  	{
   124  		Name: "ACCOUNT",
   125  		Flags: []cli.Flag{
   126  			utils.UnlockedAccountFlag,
   127  			utils.PasswordFileFlag,
   128  			utils.ExternalSignerFlag,
   129  			utils.InsecureUnlockAllowedFlag,
   130  		},
   131  	},
   132  	{
   133  		Name: "API AND CONSOLE",
   134  		Flags: []cli.Flag{
   135  			utils.IPCDisabledFlag,
   136  			utils.IPCPathFlag,
   137  			utils.HTTPEnabledFlag,
   138  			utils.HTTPListenAddrFlag,
   139  			utils.HTTPPortFlag,
   140  			utils.HTTPApiFlag,
   141  			utils.HTTPPathPrefixFlag,
   142  			utils.HTTPCORSDomainFlag,
   143  			utils.HTTPVirtualHostsFlag,
   144  			utils.WSEnabledFlag,
   145  			utils.WSListenAddrFlag,
   146  			utils.WSPortFlag,
   147  			utils.WSApiFlag,
   148  			utils.WSPathPrefixFlag,
   149  			utils.WSAllowedOriginsFlag,
   150  			utils.GraphQLEnabledFlag,
   151  			utils.GraphQLCORSDomainFlag,
   152  			utils.GraphQLVirtualHostsFlag,
   153  			utils.RPCGlobalGasCapFlag,
   154  			utils.RPCGlobalTxFeeCapFlag,
   155  			utils.AllowUnprotectedTxs,
   156  			utils.JSpathFlag,
   157  			utils.ExecFlag,
   158  			utils.PreloadJSFlag,
   159  		},
   160  	},
   161  	{
   162  		Name: "NETWORKING",
   163  		Flags: []cli.Flag{
   164  			utils.BootnodesFlag,
   165  			utils.DNSDiscoveryFlag,
   166  			utils.ListenPortFlag,
   167  			utils.MaxPeersFlag,
   168  			utils.MaxPendingPeersFlag,
   169  			utils.NATFlag,
   170  			utils.NoDiscoverFlag,
   171  			utils.DiscoveryV5Flag,
   172  			utils.NetrestrictFlag,
   173  			utils.NodeKeyFileFlag,
   174  			utils.NodeKeyHexFlag,
   175  		},
   176  	},
   177  	{
   178  		Name: "MINER",
   179  		Flags: []cli.Flag{
   180  			utils.MiningEnabledFlag,
   181  			utils.MinerThreadsFlag,
   182  			utils.MinerNotifyFlag,
   183  			utils.MinerNotifyFullFlag,
   184  			utils.MinerGasPriceFlag,
   185  			utils.MinerGasTargetFlag,
   186  			utils.MinerGasLimitFlag,
   187  			utils.MinerEtherbaseFlag,
   188  			utils.MinerExtraDataFlag,
   189  			utils.MinerRecommitIntervalFlag,
   190  			utils.MinerNoVerfiyFlag,
   191  		},
   192  	},
   193  	{
   194  		Name: "GAS PRICE ORACLE",
   195  		Flags: []cli.Flag{
   196  			utils.GpoBlocksFlag,
   197  			utils.GpoPercentileFlag,
   198  			utils.GpoMaxGasPriceFlag,
   199  			utils.GpoIgnoreGasPriceFlag,
   200  		},
   201  	},
   202  	{
   203  		Name: "VIRTUAL MACHINE",
   204  		Flags: []cli.Flag{
   205  			utils.VMEnableDebugFlag,
   206  		},
   207  	},
   208  	{
   209  		Name: "LOGGING AND DEBUGGING",
   210  		Flags: append([]cli.Flag{
   211  			utils.FakePoWFlag,
   212  			utils.NoCompactionFlag,
   213  		}, debug.Flags...),
   214  	},
   215  	{
   216  		Name:  "METRICS AND STATS",
   217  		Flags: metricsFlags,
   218  	},
   219  	{
   220  		Name: "ALIASED (deprecated)",
   221  		Flags: []cli.Flag{
   222  			utils.NoUSBFlag,
   223  			utils.LegacyRPCEnabledFlag,
   224  			utils.LegacyRPCListenAddrFlag,
   225  			utils.LegacyRPCPortFlag,
   226  			utils.LegacyRPCCORSDomainFlag,
   227  			utils.LegacyRPCVirtualHostsFlag,
   228  			utils.LegacyRPCApiFlag,
   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  }