aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/command_server.cpp
diff options
context:
space:
mode:
authorAlexander Blair <snipa@jagtech.io>2020-08-16 12:44:03 -0700
committerAlexander Blair <snipa@jagtech.io>2020-08-16 12:44:03 -0700
commitc6c4ead44ee7ecd1959a940564c3fd5c96cf1ba5 (patch)
treeb2317e82ad6ddc071b70f4509e695546e74f4269 /src/daemon/command_server.cpp
parentMerge pull request #6603 (diff)
parentWallet, daemon: From 'help_advanced' back to 'help', and new 'apropos' command (diff)
downloadmonero-c6c4ead44ee7ecd1959a940564c3fd5c96cf1ba5.tar.xz
Merge pull request #6614
fb31167b1 Wallet, daemon: From 'help_advanced' back to 'help', and new 'apropos' command (rbrunner7)
Diffstat (limited to 'src/daemon/command_server.cpp')
-rw-r--r--src/daemon/command_server.cpp37
1 files changed, 35 insertions, 2 deletions
diff --git a/src/daemon/command_server.cpp b/src/daemon/command_server.cpp
index b335116de..ac4c30726 100644
--- a/src/daemon/command_server.cpp
+++ b/src/daemon/command_server.cpp
@@ -58,6 +58,12 @@ t_command_server::t_command_server(
, "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)
, "Print the local blockchain height."
@@ -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();
}