rpc: add named arg helper

Overload the Arg and MaybeArg helpers to allow accessing arguments
by name as well.

Also update the docs to document Arg and MaybeArg separately
This commit is contained in:
stickies-v
2024-01-18 17:27:36 +00:00
parent 13525e0c24
commit bbb31269bf
3 changed files with 78 additions and 10 deletions

View File

@@ -24,6 +24,8 @@
#include <util/string.h>
#include <util/translation.h>
#include <algorithm>
#include <iterator>
#include <string_view>
#include <tuple>
@@ -728,6 +730,16 @@ std::vector<std::pair<std::string, bool>> RPCHelpMan::GetArgNames() const
return ret;
}
size_t RPCHelpMan::GetParamIndex(std::string_view key) const
{
auto it{std::find_if(
m_args.begin(), m_args.end(), [&key](const auto& arg) { return arg.GetName() == key;}
)};
CHECK_NONFATAL(it != m_args.end()); // TODO: ideally this is checked at compile time
return std::distance(m_args.begin(), it);
}
std::string RPCHelpMan::ToString() const
{
std::string ret;