From fb31167b12caccdac071bdbe5ad58f235cdb82fe Mon Sep 17 00:00:00 2001 From: rbrunner7 Date: Mon, 1 Jun 2020 10:20:59 +0200 Subject: Wallet, daemon: From 'help_advanced' back to 'help', and new 'apropos' command --- src/daemon/command_server.cpp | 37 +++++++++++++++++++++++++++++++++++-- src/daemon/command_server.h | 1 + 2 files changed, 36 insertions(+), 2 deletions(-) (limited to 'src/daemon') 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 @@ -57,6 +57,12 @@ t_command_server::t_command_server( , "help []" , "Show the help section or the documentation about a ." ); + m_command_lookup.set_handler( + "apropos" + , std::bind(&t_command_server::apropos, this, p::_1) + , "apropos [ ...]" + , "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 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& args) return true; } +bool t_command_server::apropos(const std::vector& args) +{ + if (args.empty()) + { + std::cout << "Missing keyword" << std::endl; + return true; + } + const std::vector& 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 cmd; + cmd.push_back(command); + std::pair 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(); } diff --git a/src/daemon/command_server.h b/src/daemon/command_server.h index 946d55b8c..df7198d04 100644 --- a/src/daemon/command_server.h +++ b/src/daemon/command_server.h @@ -73,6 +73,7 @@ public: private: bool help(const std::vector& args); + bool apropos(const std::vector& args); std::string get_commands_str(); std::string get_command_usage(const std::vector &args); -- cgit v1.2.3