Skip to content

Commit

Permalink
Add support for "help command subCommand" (#2210)
Browse files Browse the repository at this point in the history
  • Loading branch information
codablock authored and UdjinM6 committed Aug 10, 2018
1 parent c4c6107 commit 566fa5e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions src/rpc/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ std::vector<unsigned char> ParseHexO(const UniValue& o, std::string strKey)
* Note: This interface may still be subject to change.
*/

std::string CRPCTable::help(const std::string& strCommand) const
std::string CRPCTable::help(const std::string& strCommand, const std::string& strSubCommand) const
{
std::string strRet;
std::string category;
Expand All @@ -200,6 +200,10 @@ std::string CRPCTable::help(const std::string& strCommand) const
{
JSONRPCRequest jreq;
jreq.fHelp = true;
if (!strSubCommand.empty()) {
jreq.params.setArray();
jreq.params.push_back(strSubCommand);
}
rpcfn_type pfn = pcmd->actor;
if (setDone.insert(pfn).second)
(*pfn)(jreq);
Expand Down Expand Up @@ -234,21 +238,24 @@ std::string CRPCTable::help(const std::string& strCommand) const

UniValue help(const JSONRPCRequest& jsonRequest)
{
if (jsonRequest.fHelp || jsonRequest.params.size() > 1)
if (jsonRequest.fHelp || jsonRequest.params.size() > 2)
throw std::runtime_error(
"help ( \"command\" )\n"
"help ( \"command\" ) (\"subCommand\")\n"
"\nList all commands, or get help for a specified command.\n"
"\nArguments:\n"
"1. \"command\" (string, optional) The command to get help on\n"
"2. \"subCommand\" (string, optional) The subcommand to get help on. Please not that not all subcommands support this at the moment\n"
"\nResult:\n"
"\"text\" (string) The help text\n"
);

std::string strCommand;
std::string strCommand, strSubCommand;
if (jsonRequest.params.size() > 0)
strCommand = jsonRequest.params[0].get_str();
if (jsonRequest.params.size() > 1)
strSubCommand = jsonRequest.params[1].get_str();

return tableRPC.help(strCommand);
return tableRPC.help(strCommand, strSubCommand);
}


Expand Down
2 changes: 1 addition & 1 deletion src/rpc/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class CRPCTable
public:
CRPCTable();
const CRPCCommand* operator[](const std::string& name) const;
std::string help(const std::string& name) const;
std::string help(const std::string& strCommand, const std::string& strSubCommand) const;

/**
* Execute a method.
Expand Down

0 comments on commit 566fa5e

Please sign in to comment.