Support user-defined "str-to-str-map" options.

This commit is contained in:
Tim Allen 2018-08-21 18:24:14 +10:00
parent a91fc83bfe
commit 49ef9968c0
2 changed files with 6 additions and 2 deletions

View File

@ -120,6 +120,7 @@ are exclusively available to built-in options.
a list of `key=value` pairs. a list of `key=value` pairs.
`set -add` adds the new pair to the hashmap or replace an already `set -add` adds the new pair to the hashmap or replace an already
existing key. existing key.
Only `str-to-str-map` options can be created with `declare-option`.
== Builtin options == Builtin options

View File

@ -1446,7 +1446,8 @@ const CommandDesc declare_option_cmd = {
" str-list: list of character strings\n" " str-list: list of character strings\n"
" completions: list of completion candidates\n" " completions: list of completion candidates\n"
" line-specs: list of line specs\n" " line-specs: list of line specs\n"
" range-specs: list of range specs\n", " range-specs: list of range specs\n"
" str-to-str-map: map from strings to strings\n",
ParameterDesc{ ParameterDesc{
{ { "hidden", { false, "do not display option name when completing" } }, { { "hidden", { false, "do not display option name when completing" } },
{ "docstring", { true, "specify option description" } } }, { "docstring", { true, "specify option description" } } },
@ -1457,7 +1458,7 @@ const CommandDesc declare_option_cmd = {
make_completer( make_completer(
[](const Context& context, CompletionFlags flags, [](const Context& context, CompletionFlags flags,
const String& prefix, ByteCount cursor_pos) -> Completions { const String& prefix, ByteCount cursor_pos) -> Completions {
auto c = {"int", "bool", "str", "regex", "int-list", "str-list", "completions", "line-specs", "range-specs"}; auto c = {"int", "bool", "str", "regex", "int-list", "str-list", "completions", "line-specs", "range-specs", "str-to-str-map"};
return { 0_byte, cursor_pos, complete(prefix, cursor_pos, c) }; return { 0_byte, cursor_pos, complete(prefix, cursor_pos, c) };
}), }),
[](const ParametersParser& parser, Context& context, const ShellContext&) [](const ParametersParser& parser, Context& context, const ShellContext&)
@ -1490,6 +1491,8 @@ const CommandDesc declare_option_cmd = {
opt = &reg.declare_option<TimestampedList<LineAndSpec>>(parser[1], docstring, {}, flags); opt = &reg.declare_option<TimestampedList<LineAndSpec>>(parser[1], docstring, {}, flags);
else if (parser[0] == "range-specs") else if (parser[0] == "range-specs")
opt = &reg.declare_option<TimestampedList<RangeAndString>>(parser[1], docstring, {}, flags); opt = &reg.declare_option<TimestampedList<RangeAndString>>(parser[1], docstring, {}, flags);
else if (parser[0] == "str-to-str-map")
opt = &reg.declare_option<HashMap<String, String, MemoryDomain::Options>>(parser[1], docstring, {}, flags);
else else
throw runtime_error(format("no such option type: '{}'", parser[0])); throw runtime_error(format("no such option type: '{}'", parser[0]));