From 10d8cf64cf80826dd27f8b8f2f7b74edc6b35ecb Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 10 Aug 2015 13:53:30 +0100 Subject: [PATCH] Move option docstring obtention to OptionRegistry --- src/commands.cc | 16 ++++++---------- src/option_manager.hh | 11 +++++++---- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/commands.cc b/src/commands.cc index dcfab562..79d7471e 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -990,16 +990,12 @@ const CommandDesc set_option_cmd = { { if (params.size() < 2) return ""; - - try - { - OptionManager& options = get_scope(params[0], context).options(); - const String& docstring = options[params[1]].docstring(); - if (not docstring.empty()) - return format("{}: {}", params[1], docstring); - } - catch (runtime_error&) {} - return ""; + + auto desc = GlobalScope::instance().option_registry().option_desc(params[1]); + if (not desc or desc->docstring().empty()) + return ""; + + return format("{}: {}", desc->name(), desc->docstring()); }, [](const Context& context, CompletionFlags, CommandParameters params, size_t token_to_complete, diff --git a/src/option_manager.hh b/src/option_manager.hh index b355e6d9..4e39b7b0 100644 --- a/src/option_manager.hh +++ b/src/option_manager.hh @@ -211,13 +211,16 @@ public: return *opts.back(); } - bool option_exists(StringView name) const + const OptionDesc* option_desc(StringView name) const { - return find_if(m_descs, [&name](const std::unique_ptr& opt) { - return opt->name() == name; - }) != m_descs.end(); + auto it = find_if(m_descs, + [&name](const std::unique_ptr& opt) + { return opt->name() == name; }); + return it != m_descs.end() ? it->get() : nullptr; } + bool option_exists(StringView name) const { return option_desc(name) != nullptr; } + CandidateList complete_option_name(StringView prefix, ByteCount cursor_pos) const; private: OptionManager& m_global_manager;