github.com/core-coin/go-core/v2@v2.1.9/cmd/gocore/usage.go (about)

     1  // Copyright 2015 by the Authors
     2  // This file is part of go-core.
     3  //
     4  // go-core 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-core 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-core. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  // Contains the gocore 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/core-coin/go-core/v2/cmd/utils"
    28  	"github.com/core-coin/go-core/v2/internal/debug"
    29  	"github.com/core-coin/go-core/v2/internal/flags"
    30  )
    31  
    32  // AppHelpFlagGroups is the application flags, grouped by functionality.
    33  var AppHelpFlagGroups = []flags.FlagGroup{
    34  	{
    35  		Name: "CORE",
    36  		Flags: []cli.Flag{
    37  			configFileFlag,
    38  			utils.DataDirFlag,
    39  			utils.AncientFlag,
    40  			utils.KeyStoreDirFlag,
    41  			utils.LedFlag,
    42  			utils.BTTPFlag,
    43  			utils.LedGPIOPortFlag,
    44  			utils.NetworkIdFlag,
    45  			utils.DevinFlag,
    46  			utils.SyncModeFlag,
    47  			utils.ExitWhenSyncedFlag,
    48  			utils.GCModeFlag,
    49  			utils.TxLookupLimitFlag,
    50  			utils.XcbStatsURLFlag,
    51  			utils.IdentityFlag,
    52  			utils.LightKDFFlag,
    53  			utils.WhitelistFlag,
    54  		},
    55  	},
    56  	{
    57  		Name: "LIGHT CLIENT",
    58  		Flags: []cli.Flag{
    59  			utils.LightServeFlag,
    60  			utils.LightIngressFlag,
    61  			utils.LightEgressFlag,
    62  			utils.LightMaxPeersFlag,
    63  			utils.UltraLightServersFlag,
    64  			utils.UltraLightFractionFlag,
    65  			utils.UltraLightOnlyAnnounceFlag,
    66  			utils.LightNoPruneFlag,
    67  		},
    68  	},
    69  	{
    70  		Name: "DEVELOPER CHAIN",
    71  		Flags: []cli.Flag{
    72  			utils.DeveloperFlag,
    73  			utils.DeveloperPeriodFlag,
    74  		},
    75  	},
    76  	{
    77  		Name: "TRANSACTION POOL",
    78  		Flags: []cli.Flag{
    79  			utils.TxPoolLocalsFlag,
    80  			utils.TxPoolNoLocalsFlag,
    81  			utils.TxPoolJournalFlag,
    82  			utils.TxPoolRejournalFlag,
    83  			utils.TxPoolPriceLimitFlag,
    84  			utils.TxPoolPriceBumpFlag,
    85  			utils.TxPoolAccountSlotsFlag,
    86  			utils.TxPoolGlobalSlotsFlag,
    87  			utils.TxPoolAccountQueueFlag,
    88  			utils.TxPoolGlobalQueueFlag,
    89  			utils.TxPoolLifetimeFlag,
    90  		},
    91  	},
    92  	{
    93  		Name: "PERFORMANCE TUNING",
    94  		Flags: []cli.Flag{
    95  			utils.CacheFlag,
    96  			utils.CacheDatabaseFlag,
    97  			utils.CacheTrieFlag,
    98  			utils.CacheTrieJournalFlag,
    99  			utils.CacheTrieRejournalFlag,
   100  			utils.CacheGCFlag,
   101  			utils.CacheSnapshotFlag,
   102  			utils.CacheNoPrefetchFlag,
   103  			utils.CachePreimagesFlag,
   104  		},
   105  	},
   106  	{
   107  		Name: "ACCOUNT",
   108  		Flags: []cli.Flag{
   109  			utils.UnlockedAccountFlag,
   110  			utils.PasswordFileFlag,
   111  			utils.ExternalSignerFlag,
   112  			utils.InsecureUnlockAllowedFlag,
   113  		},
   114  	},
   115  	{
   116  		Name: "API AND CONSOLE",
   117  		Flags: []cli.Flag{
   118  			utils.IPCDisabledFlag,
   119  			utils.IPCPathFlag,
   120  			utils.HTTPEnabledFlag,
   121  			utils.HTTPListenAddrFlag,
   122  			utils.HTTPPortFlag,
   123  			utils.HTTPApiFlag,
   124  			utils.HTTPPathPrefixFlag,
   125  			utils.HTTPCORSDomainFlag,
   126  			utils.HTTPVirtualHostsFlag,
   127  			utils.WSEnabledFlag,
   128  			utils.WSListenAddrFlag,
   129  			utils.WSPortFlag,
   130  			utils.WSApiFlag,
   131  			utils.WSPathPrefixFlag,
   132  			utils.WSAllowedOriginsFlag,
   133  			utils.JWTSecretFlag,
   134  			utils.AuthListenFlag,
   135  			utils.AuthPortFlag,
   136  			utils.AuthVirtualHostsFlag,
   137  			utils.GraphQLEnabledFlag,
   138  			utils.GraphQLCORSDomainFlag,
   139  			utils.GraphQLVirtualHostsFlag,
   140  			utils.RPCGlobalEnergyCapFlag,
   141  			utils.RPCGlobalTxFeeCapFlag,
   142  			utils.JSpathFlag,
   143  			utils.ExecFlag,
   144  			utils.PreloadJSFlag,
   145  		},
   146  	},
   147  	{
   148  		Name: "NETWORKING",
   149  		Flags: []cli.Flag{
   150  			utils.BootnodesFlag,
   151  			utils.DNSDiscoveryFlag,
   152  			utils.EnableDNSDiscoveryFlag,
   153  			utils.ListenPortFlag,
   154  			utils.MaxPeersFlag,
   155  			utils.MaxPendingPeersFlag,
   156  			utils.NATFlag,
   157  			utils.NoDiscoverFlag,
   158  			utils.DiscoveryV5Flag,
   159  			utils.NetrestrictFlag,
   160  			utils.NodeKeyFileFlag,
   161  			utils.NodeKeyHexFlag,
   162  			utils.NtpServerFlag,
   163  		},
   164  	},
   165  	{
   166  		Name: "MINER",
   167  		Flags: []cli.Flag{
   168  			utils.MiningEnabledFlag,
   169  			utils.MinerThreadsFlag,
   170  			utils.MinerNotifyFlag,
   171  			utils.MinerEnergyPriceFlag,
   172  			utils.MinerEnergyTargetFlag,
   173  			utils.MinerEnergyLimitFlag,
   174  			utils.MinerCorebaseFlag,
   175  			utils.MinerExtraDataFlag,
   176  			utils.MinerRecommitIntervalFlag,
   177  			utils.MinerNoVerfiyFlag,
   178  		},
   179  	},
   180  	{
   181  		Name: "ENERGY PRICE ORACLE",
   182  		Flags: []cli.Flag{
   183  			utils.GpoBlocksFlag,
   184  			utils.GpoPercentileFlag,
   185  			utils.GpoMaxEnergyPriceFlag,
   186  		},
   187  	},
   188  	{
   189  		Name: "VIRTUAL MACHINE",
   190  		Flags: []cli.Flag{
   191  			utils.VMEnableDebugFlag,
   192  			utils.CVMInterpreterFlag,
   193  			utils.EWASMInterpreterFlag,
   194  		},
   195  	},
   196  	{
   197  		Name: "LOGGING AND DEBUGGING",
   198  		Flags: append([]cli.Flag{
   199  			utils.FakePoWFlag,
   200  			utils.NoCompactionFlag,
   201  		}, debug.Flags...),
   202  	},
   203  	{
   204  		Name:  "METRICS AND STATS",
   205  		Flags: metricsFlags,
   206  	},
   207  	{
   208  		Name: "MISC",
   209  		Flags: []cli.Flag{
   210  			utils.SnapshotFlag,
   211  			cli.HelpFlag,
   212  		},
   213  	},
   214  }
   215  
   216  func init() {
   217  	// Override the default app help template
   218  	cli.AppHelpTemplate = flags.AppHelpTemplate
   219  
   220  	// Override the default app help printer, but only for the global app help
   221  	originalHelpPrinter := cli.HelpPrinter
   222  	cli.HelpPrinter = func(w io.Writer, tmpl string, data interface{}) {
   223  		if tmpl == flags.AppHelpTemplate {
   224  			// Iterate over all the flags and add any uncategorized ones
   225  			categorized := make(map[string]struct{})
   226  			for _, group := range AppHelpFlagGroups {
   227  				for _, flag := range group.Flags {
   228  					categorized[flag.String()] = struct{}{}
   229  				}
   230  			}
   231  			// Render out custom usage screen
   232  			originalHelpPrinter(w, tmpl, flags.HelpData{App: data, FlagGroups: AppHelpFlagGroups})
   233  		} else if tmpl == flags.CommandHelpTemplate {
   234  			// Iterate over all command specific flags and categorize them
   235  			categorized := make(map[string][]cli.Flag)
   236  			for _, flag := range data.(cli.Command).Flags {
   237  				if _, ok := categorized[flag.String()]; !ok {
   238  					categorized[flags.FlagCategory(flag, AppHelpFlagGroups)] = append(categorized[flags.FlagCategory(flag, AppHelpFlagGroups)], flag)
   239  				}
   240  			}
   241  
   242  			// sort to get a stable ordering
   243  			sorted := make([]flags.FlagGroup, 0, len(categorized))
   244  			for cat, flgs := range categorized {
   245  				sorted = append(sorted, flags.FlagGroup{Name: cat, Flags: flgs})
   246  			}
   247  			sort.Sort(flags.ByCategory(sorted))
   248  
   249  			// add sorted array to data and render with default printer
   250  			originalHelpPrinter(w, tmpl, map[string]interface{}{
   251  				"cmd":              data,
   252  				"categorizedFlags": sorted,
   253  			})
   254  		} else {
   255  			originalHelpPrinter(w, tmpl, data)
   256  		}
   257  	}
   258  }