diff options
author | Riccardo Spagni <ric@spagni.net> | 2017-12-02 09:22:43 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2017-12-02 09:22:43 +0200 |
commit | 1fec38e7369bda53db7e7ed7b757d27165ce1108 (patch) | |
tree | 9a5b7a8382fd0541c8350fb4793a57fbba20e1da /contrib | |
parent | Merge pull request #2831 (diff) | |
parent | Added command descriptions (diff) | |
download | monero-1fec38e7369bda53db7e7ed7b757d27165ce1108.tar.xz |
Merge pull request #2832
287dde63 Added command descriptions (Cifrado)
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/epee/include/console_handler.h | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/contrib/epee/include/console_handler.h b/contrib/epee/include/console_handler.h index b8336b270..6d369d4d8 100644 --- a/contrib/epee/include/console_handler.h +++ b/contrib/epee/include/console_handler.h @@ -456,29 +456,35 @@ eof: class command_handler { public: typedef boost::function<bool (const std::vector<std::string> &)> callback; - typedef std::map<std::string, std::pair<callback, std::string> > lookup; + typedef std::map<std::string, std::pair<callback, std::pair<std::string, std::string>>> lookup; std::string get_usage() { std::stringstream ss; - size_t max_command_len = 0; - for(auto& x:m_command_handlers) - if(x.first.size() > max_command_len) - max_command_len = x.first.size(); for(auto& x:m_command_handlers) { - ss.width(max_command_len + 3); - ss << std::left << x.first << x.second.second << ENDL; + ss << x.second.second.first << ENDL; } return ss.str(); } - void set_handler(const std::string& cmd, const callback& hndlr, const std::string& usage = "") + std::pair<std::string, std::string> get_documentation(const std::vector<std::string>& cmd) + { + if(cmd.empty()) + return std::make_pair("", ""); + auto it = m_command_handlers.find(cmd.front()); + if(it == m_command_handlers.end()) + return std::make_pair("", ""); + return it->second.second; + } + + void set_handler(const std::string& cmd, const callback& hndlr, const std::string& usage = "", const std::string& description = "") { lookup::mapped_type & vt = m_command_handlers[cmd]; vt.first = hndlr; - vt.second = usage; + vt.second.first = description.empty() ? cmd : usage; + vt.second.second = description.empty() ? usage : description; #ifdef HAVE_READLINE rdln::readline_buffer::add_completion(cmd); #endif |