Skip to content

Commit 681ebcc

Browse files
committed
netinfo: rename and hoist max level constant to use in top-level help
to avoid overlooking to update the top-level help if the value of the constant changes.
1 parent e7d307c commit 681ebcc

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/bitcoin-cli.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ static const int DEFAULT_HTTP_CLIENT_TIMEOUT=900;
5757
static constexpr int DEFAULT_WAIT_CLIENT_TIMEOUT = 0;
5858
static const bool DEFAULT_NAMED=false;
5959
static const int CONTINUE_EXECUTION=-1;
60+
static constexpr uint8_t NETINFO_MAX_LEVEL{4};
6061
static constexpr int8_t UNKNOWN_NETWORK{-1};
6162
// See GetNetworkName() in netbase.cpp
6263
static constexpr std::array NETWORKS{"not_publicly_routable", "ipv4", "ipv6", "onion", "i2p", "cjdns", "internal"};
@@ -90,7 +91,7 @@ static void SetupCliArgs(ArgsManager& argsman)
9091
ArgsManager::ALLOW_ANY, OptionsCategory::CLI_COMMANDS);
9192
argsman.AddArg("-addrinfo", "Get the number of addresses known to the node, per network and total, after filtering for quality and recency. The total number of addresses known to the node may be higher.", ArgsManager::ALLOW_ANY, OptionsCategory::CLI_COMMANDS);
9293
argsman.AddArg("-getinfo", "Get general information from the remote server. Note that unlike server-side RPC calls, the output of -getinfo is the result of multiple non-atomic requests. Some entries in the output may represent results from different states (e.g. wallet balance may be as of a different block from the chain state reported)", ArgsManager::ALLOW_ANY, OptionsCategory::CLI_COMMANDS);
93-
argsman.AddArg("-netinfo", "Get network peer connection information from the remote server. An optional integer argument from 0 to 4 can be passed for different peers listings (default: 0). Pass \"help\" for detailed help documentation.", ArgsManager::ALLOW_ANY, OptionsCategory::CLI_COMMANDS);
94+
argsman.AddArg("-netinfo", strprintf("Get network peer connection information from the remote server. An optional integer argument from 0 to %d can be passed for different peers listings (default: 0). Pass \"help\" for detailed help documentation.", NETINFO_MAX_LEVEL), ArgsManager::ALLOW_ANY, OptionsCategory::CLI_COMMANDS);
9495

9596
SetupChainParamsBaseOptions(argsman);
9697
argsman.AddArg("-color=<when>", strprintf("Color setting for CLI output (default: %s). Valid values: always, auto (add color codes when standard output is connected to a terminal and OS is not WIN32), never.", DEFAULT_COLOR_SETTING), ArgsManager::ALLOW_ANY | ArgsManager::DISALLOW_NEGATION, OptionsCategory::OPTIONS);
@@ -379,7 +380,6 @@ class GetinfoRequestHandler: public BaseRequestHandler
379380
class NetinfoRequestHandler : public BaseRequestHandler
380381
{
381382
private:
382-
static constexpr uint8_t MAX_DETAIL_LEVEL{4};
383383
std::array<std::array<uint16_t, NETWORKS.size() + 1>, 3> m_counts{{{}}}; //!< Peer counts by (in/out/total, networks/total)
384384
uint8_t m_block_relay_peers_count{0};
385385
uint8_t m_manual_peers_count{0};
@@ -477,7 +477,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
477477
if (!args.empty()) {
478478
uint8_t n{0};
479479
if (ParseUInt8(args.at(0), &n)) {
480-
m_details_level = std::min(n, MAX_DETAIL_LEVEL);
480+
m_details_level = std::min(n, NETINFO_MAX_LEVEL);
481481
} else {
482482
throw std::runtime_error(strprintf("invalid -netinfo argument: %s\nFor more information, run: bitcoin-cli -netinfo help", args.at(0)));
483483
}
@@ -652,12 +652,12 @@ class NetinfoRequestHandler : public BaseRequestHandler
652652
"Returns a network peer connections dashboard with information from the remote server.\n"
653653
"This human-readable interface will change regularly and is not intended to be a stable API.\n"
654654
"Under the hood, -netinfo fetches the data by calling getpeerinfo and getnetworkinfo.\n"
655-
+ strprintf("An optional integer argument from 0 to %d can be passed for different peers listings; %d to 255 are parsed as %d.\n", MAX_DETAIL_LEVEL, MAX_DETAIL_LEVEL, MAX_DETAIL_LEVEL) +
655+
+ strprintf("An optional integer argument from 0 to %d can be passed for different peers listings; values from %d to 255 are parsed as %d.\n", NETINFO_MAX_LEVEL, NETINFO_MAX_LEVEL, NETINFO_MAX_LEVEL) +
656656
"Pass \"help\" to see this detailed help documentation.\n"
657657
"If more than one argument is passed, only the first one is read and parsed.\n"
658658
"Suggestion: use with the Linux watch(1) command for a live dashboard; see example below.\n\n"
659659
"Arguments:\n"
660-
+ strprintf("1. level (integer 0-%d, optional) Specify the info level of the peers dashboard (default 0):\n", MAX_DETAIL_LEVEL) +
660+
+ strprintf("1. level (integer 0-%d, optional) Specify the info level of the peers dashboard (default 0):\n", NETINFO_MAX_LEVEL) +
661661
" 0 - Peer counts for each reachable network as well as for block relay peers\n"
662662
" and manual peers, and the list of local addresses and ports\n"
663663
" 1 - Like 0 but preceded by a peers listing (without address and version columns)\n"
@@ -666,7 +666,7 @@ class NetinfoRequestHandler : public BaseRequestHandler
666666
" 4 - Like 1 but with both address and version columns\n"
667667
"2. help (string \"help\", optional) Print this help documentation instead of the dashboard.\n\n"
668668
"Result:\n\n"
669-
+ strprintf("* The peers listing in levels 1-%d displays all of the peers sorted by direction and minimum ping time:\n\n", MAX_DETAIL_LEVEL) +
669+
+ strprintf("* The peers listing in levels 1-%d displays all of the peers sorted by direction and minimum ping time:\n\n", NETINFO_MAX_LEVEL) +
670670
" Column Description\n"
671671
" ------ -----------\n"
672672
" <-> Direction\n"
@@ -716,9 +716,9 @@ class NetinfoRequestHandler : public BaseRequestHandler
716716
"The same, preceded by a peers listing without address and version columns\n"
717717
"> bitcoin-cli -netinfo 1\n\n"
718718
"Full dashboard\n"
719-
+ strprintf("> bitcoin-cli -netinfo %d\n\n", MAX_DETAIL_LEVEL) +
719+
+ strprintf("> bitcoin-cli -netinfo %d\n\n", NETINFO_MAX_LEVEL) +
720720
"Full live dashboard, adjust --interval or --no-title as needed (Linux)\n"
721-
+ strprintf("> watch --interval 1 --no-title bitcoin-cli -netinfo %d\n\n", MAX_DETAIL_LEVEL) +
721+
+ strprintf("> watch --interval 1 --no-title bitcoin-cli -netinfo %d\n\n", NETINFO_MAX_LEVEL) +
722722
"See this help\n"
723723
"> bitcoin-cli -netinfo help\n"};
724724
};

0 commit comments

Comments
 (0)