Skip to content

Commit

Permalink
chore: improve bor server --help (#1063)
Browse files Browse the repository at this point in the history
* chore: update `txarrivalwait` flag description

* chore: update docs

* chore: update other flags

* fix: doc generation is now deterministic

* chore: remove debug

* feat: sort options in `bor server --help`

* fix: prealloc array

* fix: lint issues

* internal/cli: remove nolint

---------

Co-authored-by: marcello33 <marcelloardizzone@hotmail.it>
Co-authored-by: Manav Darji <manavdarji.india@gmail.com>
  • Loading branch information
3 people authored Nov 7, 2023
1 parent bc338be commit 22a2b63
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 130 deletions.
4 changes: 2 additions & 2 deletions docs/cli/attach.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ Connect to remote Bor IPC console.

- ```exec```: Command to run in remote console

- ```preload```: Comma separated list of JavaScript files to preload into the console
- ```jspath```: JavaScript root path for `loadScript`

- ```jspath```: JavaScript root path for `loadScript`
- ```preload```: Comma separated list of JavaScript files to preload into the console
14 changes: 9 additions & 5 deletions docs/cli/bootnode.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@

## Options

- ```listen-addr```: listening address of bootnode (<ip>:<port>) (default: 0.0.0.0:30303)

- ```v5```: Enable UDP v5 (default: false)
- ```dry-run```: validates parameters and prints bootnode configurations, but does not start bootnode (default: false)

- ```verbosity```: Logging verbosity (5=trace|4=debug|3=info|2=warn|1=error|0=crit) (default: 3)
- ```listen-addr```: listening address of bootnode (<ip>:<port>) (default: 0.0.0.0:30303)

- ```log-level```: log level (trace|debug|info|warn|error|crit), will be deprecated soon. Use verbosity instead (default: info)

- ```metrics```: Enable metrics collection and reporting (default: true)

- ```nat```: port mapping mechanism (any|none|upnp|pmp|extip:<IP>) (default: none)

- ```node-key```: file or hex node key

- ```prometheus-addr```: listening address of bootnode (<ip>:<port>) (default: 127.0.0.1:7071)

- ```save-key```: path to save the ecdsa private key

- ```dry-run```: validates parameters and prints bootnode configurations, but does not start bootnode (default: false)
- ```v5```: Enable UDP v5 (default: false)

- ```verbosity```: Logging verbosity (5=trace|4=debug|3=info|2=warn|1=error|0=crit) (default: 3)
4 changes: 2 additions & 2 deletions docs/cli/debug_pprof.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ The ```debug pprof <enode>``` command will create an archive containing bor ppro

- ```address```: Address of the grpc endpoint (default: 127.0.0.1:3131)

- ```seconds```: seconds to profile (default: 2)

- ```output```: Output directory

- ```seconds```: seconds to profile (default: 2)

- ```skiptrace```: Skip running the trace (default: false)
224 changes: 112 additions & 112 deletions docs/cli/server.md

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/cli/snapshot_prune-state.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ The ```bor snapshot prune-state``` command will prune historical state data with

## Options

- ```datadir```: Path of the data directory to store information
- ```bloomfilter.size```: Size of the bloom filter (default: 2048)

- ```keystore```: Path of the data directory to store keys
- ```datadir```: Path of the data directory to store information

- ```datadir.ancient```: Path of the ancient data directory to store information

- ```bloomfilter.size```: Size of the bloom filter (default: 2048)
- ```keystore```: Path of the data directory to store keys

### Cache Options

Expand Down
20 changes: 19 additions & 1 deletion internal/cli/flagset/flagset.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ type FlagVar struct {
Value Updatable
}

// ByName implements sort.Interface for []*FlagVar based on the Name field.
type ByName []*FlagVar

func (a ByName) Len() int { return len(a) }
func (a ByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByName) Less(i, j int) bool { return a[i].Name < a[j].Name }

func (f *Flagset) addFlag(fl *FlagVar) {
f.flags[fl.Name] = fl
}
Expand All @@ -48,7 +55,14 @@ func (f *Flagset) Help() string {

items := []string{}

flags := []*FlagVar{}
for _, item := range f.flags {
flags = append(flags, item)
}

sort.Sort(ByName(flags))

for _, item := range flags {
if item.Default != nil {
items = append(items, fmt.Sprintf(" -%s\n %s (default: %v)", item.Name, item.Usage, item.Default))
} else {
Expand Down Expand Up @@ -102,7 +116,11 @@ func (f *Flagset) MarkDown() string {
items = append(items, fmt.Sprintf("### %s Options", k))
}

for _, item := range groups[k] {
flags := make([]*FlagVar, len(groups[k]))
copy(flags, groups[k])
sort.Sort(ByName(flags))

for _, item := range flags {
if item.Default != nil {
items = append(items, fmt.Sprintf("- ```%s```: %s (default: %v)", item.Name, item.Usage, item.Default))
} else {
Expand Down
10 changes: 5 additions & 5 deletions internal/cli/server/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (c *Command) Flags(config *Config) *flagset.Flagset {
})
f.IntFlag(&flagset.IntFlag{
Name: "verbosity",
Usage: "Logging verbosity for the server (5=trace|4=debug|3=info|2=warn|1=error|0=crit), default = 3",
Usage: "Logging verbosity for the server (5=trace|4=debug|3=info|2=warn|1=error|0=crit)",
Value: &c.cliConfig.Verbosity,
Default: c.cliConfig.Verbosity,
})
Expand Down Expand Up @@ -71,13 +71,13 @@ func (c *Command) Flags(config *Config) *flagset.Flagset {
})
f.Uint64Flag(&flagset.Uint64Flag{
Name: "rpc.batchlimit",
Usage: "Maximum number of messages in a batch (default=100, use 0 for no limits)",
Usage: "Maximum number of messages in a batch (use 0 for no limits)",
Value: &c.cliConfig.RPCBatchLimit,
Default: c.cliConfig.RPCBatchLimit,
})
f.Uint64Flag(&flagset.Uint64Flag{
Name: "rpc.returndatalimit",
Usage: "Maximum size (in bytes) a result of an rpc request could have (default=100000, use 0 for no limits)",
Usage: "Maximum size (in bytes) a result of an rpc request could have (use 0 for no limits)",
Value: &c.cliConfig.RPCReturnDataLimit,
Default: c.cliConfig.RPCReturnDataLimit,
})
Expand Down Expand Up @@ -433,7 +433,7 @@ func (c *Command) Flags(config *Config) *flagset.Flagset {
})
f.Uint64Flag(&flagset.Uint64Flag{
Name: "cache.triesinmemory",
Usage: "Number of block states (tries) to keep in memory (default = 128)",
Usage: "Number of block states (tries) to keep in memory",
Value: &c.cliConfig.Cache.TriesInMemory,
Default: c.cliConfig.Cache.TriesInMemory,
Group: "Cache",
Expand Down Expand Up @@ -788,7 +788,7 @@ func (c *Command) Flags(config *Config) *flagset.Flagset {
})
f.DurationFlag(&flagset.DurationFlag{
Name: "txarrivalwait",
Usage: "Maximum duration to wait for a transaction before explicitly requesting it (defaults to 500ms)",
Usage: "Maximum duration to wait for a transaction before explicitly requesting it",
Value: &c.cliConfig.P2P.TxArrivalWait,
Default: c.cliConfig.P2P.TxArrivalWait,
Group: "P2P",
Expand Down

0 comments on commit 22a2b63

Please sign in to comment.