github.com/prysmaticlabs/prysm@v1.4.4/cmd/beacon-chain/usage.go (about)

     1  // This code was adapted from https://github.com/ethereum/go-ethereum/blob/master/cmd/geth/usage.go
     2  package main
     3  
     4  import (
     5  	"io"
     6  	"sort"
     7  
     8  	"github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags"
     9  	"github.com/prysmaticlabs/prysm/shared/cmd"
    10  	"github.com/prysmaticlabs/prysm/shared/debug"
    11  	"github.com/prysmaticlabs/prysm/shared/featureconfig"
    12  	"github.com/urfave/cli/v2"
    13  )
    14  
    15  var appHelpTemplate = `NAME:
    16     {{.App.Name}} - {{.App.Usage}}
    17  USAGE:
    18     {{.App.HelpName}} [options]{{if .App.Commands}} command [command options]{{end}} {{if .App.ArgsUsage}}{{.App.ArgsUsage}}{{else}}[arguments...]{{end}}
    19     {{if .App.Version}}
    20  AUTHOR:
    21     {{range .App.Authors}}{{ . }}{{end}}
    22     {{end}}{{if .App.Commands}}
    23  GLOBAL OPTIONS:
    24     {{range .App.Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}}
    25     {{end}}{{end}}{{if .FlagGroups}}
    26  {{range .FlagGroups}}{{.Name}} OPTIONS:
    27     {{range .Flags}}{{.}}
    28     {{end}}
    29  {{end}}{{end}}{{if .App.Copyright }}
    30  COPYRIGHT:
    31     {{.App.Copyright}}
    32  VERSION:
    33     {{.App.Version}}
    34     {{end}}{{if len .App.Authors}}
    35     {{end}}
    36  `
    37  
    38  type flagGroup struct {
    39  	Name  string
    40  	Flags []cli.Flag
    41  }
    42  
    43  var appHelpFlagGroups = []flagGroup{
    44  	{
    45  		Name: "cmd",
    46  		Flags: []cli.Flag{
    47  			cmd.MinimalConfigFlag,
    48  			cmd.E2EConfigFlag,
    49  			cmd.RPCMaxPageSizeFlag,
    50  			cmd.NoDiscovery,
    51  			cmd.BootstrapNode,
    52  			cmd.RelayNode,
    53  			cmd.P2PUDPPort,
    54  			cmd.P2PTCPPort,
    55  			cmd.DataDirFlag,
    56  			cmd.VerbosityFlag,
    57  			cmd.EnableTracingFlag,
    58  			cmd.TracingProcessNameFlag,
    59  			cmd.TracingEndpointFlag,
    60  			cmd.TraceSampleFractionFlag,
    61  			cmd.MonitoringHostFlag,
    62  			cmd.BackupWebhookOutputDir,
    63  			cmd.EnableBackupWebhookFlag,
    64  			flags.MonitoringPortFlag,
    65  			cmd.DisableMonitoringFlag,
    66  			cmd.MaxGoroutines,
    67  			cmd.ForceClearDB,
    68  			cmd.ClearDB,
    69  			cmd.ConfigFileFlag,
    70  			cmd.ChainConfigFileFlag,
    71  			cmd.GrpcMaxCallRecvMsgSizeFlag,
    72  			cmd.AcceptTosFlag,
    73  			cmd.RestoreSourceFileFlag,
    74  			cmd.RestoreTargetDirFlag,
    75  			cmd.BoltMMapInitialSizeFlag,
    76  		},
    77  	},
    78  	{
    79  		Name: "debug",
    80  		Flags: []cli.Flag{
    81  			debug.PProfFlag,
    82  			debug.PProfAddrFlag,
    83  			debug.PProfPortFlag,
    84  			debug.MemProfileRateFlag,
    85  			debug.CPUProfileFlag,
    86  			debug.TraceFlag,
    87  			debug.BlockProfileRateFlag,
    88  			debug.MutexProfileFractionFlag,
    89  		},
    90  	},
    91  	{
    92  		Name: "beacon-chain",
    93  		Flags: []cli.Flag{
    94  			flags.InteropMockEth1DataVotesFlag,
    95  			flags.InteropGenesisStateFlag,
    96  			flags.DepositContractFlag,
    97  			flags.ContractDeploymentBlock,
    98  			flags.RPCHost,
    99  			flags.RPCPort,
   100  			flags.CertFlag,
   101  			flags.KeyFlag,
   102  			flags.DisableGRPCGateway,
   103  			flags.GRPCGatewayHost,
   104  			flags.GRPCGatewayPort,
   105  			flags.EthApiPort,
   106  			flags.GPRCGatewayCorsDomain,
   107  			flags.HTTPWeb3ProviderFlag,
   108  			flags.FallbackWeb3ProviderFlag,
   109  			flags.SetGCPercent,
   110  			flags.HeadSync,
   111  			flags.DisableSync,
   112  			flags.SlotsPerArchivedPoint,
   113  			flags.DisableDiscv5,
   114  			flags.BlockBatchLimit,
   115  			flags.BlockBatchLimitBurstFactor,
   116  			flags.EnableDebugRPCEndpoints,
   117  			flags.SubscribeToAllSubnets,
   118  			flags.HistoricalSlasherNode,
   119  			flags.ChainID,
   120  			flags.NetworkID,
   121  			flags.WeakSubjectivityCheckpt,
   122  			flags.Eth1HeaderReqLimit,
   123  			flags.GenesisStatePath,
   124  		},
   125  	},
   126  	{
   127  		Name: "p2p",
   128  		Flags: []cli.Flag{
   129  			cmd.P2PIP,
   130  			cmd.P2PHost,
   131  			cmd.P2PHostDNS,
   132  			cmd.P2PMaxPeers,
   133  			cmd.P2PPrivKey,
   134  			cmd.P2PMetadata,
   135  			cmd.P2PAllowList,
   136  			cmd.P2PDenyList,
   137  			cmd.StaticPeers,
   138  			cmd.EnableUPnPFlag,
   139  			flags.MinSyncPeers,
   140  		},
   141  	},
   142  	{
   143  		Name: "log",
   144  		Flags: []cli.Flag{
   145  			cmd.LogFormat,
   146  			cmd.LogFileName,
   147  		},
   148  	},
   149  	{
   150  		Name:  "features",
   151  		Flags: featureconfig.ActiveFlags(featureconfig.BeaconChainFlags),
   152  	},
   153  	{
   154  		Name: "interop",
   155  		Flags: []cli.Flag{
   156  			flags.InteropGenesisStateFlag,
   157  			flags.InteropGenesisTimeFlag,
   158  			flags.InteropNumValidatorsFlag,
   159  		},
   160  	},
   161  }
   162  
   163  func init() {
   164  	cli.AppHelpTemplate = appHelpTemplate
   165  
   166  	type helpData struct {
   167  		App        interface{}
   168  		FlagGroups []flagGroup
   169  	}
   170  
   171  	originalHelpPrinter := cli.HelpPrinter
   172  	cli.HelpPrinter = func(w io.Writer, tmpl string, data interface{}) {
   173  		if tmpl == appHelpTemplate {
   174  			for _, group := range appHelpFlagGroups {
   175  				sort.Sort(cli.FlagsByName(group.Flags))
   176  			}
   177  			originalHelpPrinter(w, tmpl, helpData{data, appHelpFlagGroups})
   178  		} else {
   179  			originalHelpPrinter(w, tmpl, data)
   180  		}
   181  	}
   182  }