Wallet, daemon: From 'help_advanced' back to 'help', and new 'apropos' command

This commit is contained in:
rbrunner7
2020-06-01 10:20:59 +02:00
parent 5d850dde99
commit fb31167b12
7 changed files with 135 additions and 49 deletions

View File

@@ -57,6 +57,12 @@ t_command_server::t_command_server(
, "help [<command>]"
, "Show the help section or the documentation about a <command>."
);
m_command_lookup.set_handler(
"apropos"
, std::bind(&t_command_server::apropos, this, p::_1)
, "apropos <keyword> [<keyword> ...]"
, "Search all command descriptions for keyword(s)."
);
m_command_lookup.set_handler(
"print_height"
, std::bind(&t_command_parser_executor::print_height, &m_parser, p::_1)
@@ -349,7 +355,7 @@ bool t_command_server::start_handling(std::function<void(void)> exit_handler)
{
if (m_is_rpc) return false;
m_command_lookup.start_handling("", get_commands_str(), exit_handler);
m_command_lookup.start_handling("", "Use \"help\" to list all commands and their usage\n", exit_handler);
return true;
}
@@ -374,6 +380,33 @@ bool t_command_server::help(const std::vector<std::string>& args)
return true;
}
bool t_command_server::apropos(const std::vector<std::string>& args)
{
if (args.empty())
{
std::cout << "Missing keyword" << std::endl;
return true;
}
const std::vector<std::string>& command_list = m_command_lookup.get_command_list(args);
if (command_list.empty())
{
std::cout << "Nothing found" << std::endl;
return true;
}
std::cout << std::endl;
for(auto const& command:command_list)
{
std::vector<std::string> cmd;
cmd.push_back(command);
std::pair<std::string, std::string> documentation = m_command_lookup.get_documentation(cmd);
std::cout << " " << documentation.first << std::endl;
}
std::cout << std::endl;
return true;
}
std::string t_command_server::get_commands_str()
{
std::stringstream ss;
@@ -382,7 +415,7 @@ std::string t_command_server::get_commands_str()
std::string usage = m_command_lookup.get_usage();
boost::replace_all(usage, "\n", "\n ");
usage.insert(0, " ");
ss << usage << std::endl;
ss << usage;
return ss.str();
}