Move option docstring obtention to OptionRegistry

This commit is contained in:
Maxime Coste 2015-08-10 13:53:30 +01:00
parent bfb116b8b4
commit 10d8cf64cf
2 changed files with 13 additions and 14 deletions

View File

@ -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,

View File

@ -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<OptionDesc>& opt) {
return opt->name() == name;
}) != m_descs.end();
auto it = find_if(m_descs,
[&name](const std::unique_ptr<OptionDesc>& 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;