Move option docstring obtention to OptionRegistry
This commit is contained in:
parent
bfb116b8b4
commit
10d8cf64cf
|
@ -990,16 +990,12 @@ const CommandDesc set_option_cmd = {
|
||||||
{
|
{
|
||||||
if (params.size() < 2)
|
if (params.size() < 2)
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
try
|
auto desc = GlobalScope::instance().option_registry().option_desc(params[1]);
|
||||||
{
|
if (not desc or desc->docstring().empty())
|
||||||
OptionManager& options = get_scope(params[0], context).options();
|
return "";
|
||||||
const String& docstring = options[params[1]].docstring();
|
|
||||||
if (not docstring.empty())
|
return format("{}: {}", desc->name(), desc->docstring());
|
||||||
return format("{}: {}", params[1], docstring);
|
|
||||||
}
|
|
||||||
catch (runtime_error&) {}
|
|
||||||
return "";
|
|
||||||
},
|
},
|
||||||
[](const Context& context, CompletionFlags,
|
[](const Context& context, CompletionFlags,
|
||||||
CommandParameters params, size_t token_to_complete,
|
CommandParameters params, size_t token_to_complete,
|
||||||
|
|
|
@ -211,13 +211,16 @@ public:
|
||||||
return *opts.back();
|
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) {
|
auto it = find_if(m_descs,
|
||||||
return opt->name() == name;
|
[&name](const std::unique_ptr<OptionDesc>& opt)
|
||||||
}) != m_descs.end();
|
{ 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;
|
CandidateList complete_option_name(StringView prefix, ByteCount cursor_pos) const;
|
||||||
private:
|
private:
|
||||||
OptionManager& m_global_manager;
|
OptionManager& m_global_manager;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user