diff options
| author | Maxime Coste <mawww@kakoune.org> | 2018-05-30 23:23:38 +1000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2018-07-05 07:54:28 +1000 |
| commit | b548dd3a6f369e5a244fdcdca55061513026f82a (patch) | |
| tree | 1ca672c1d6f976a74f34d37f75fd68a83933fbe1 /src/option.hh | |
| parent | 5eeec8bd4d24882ea443c4441f696257b8cb68c4 (diff) | |
Change option lists to be specified as separate arguments on commands line
Option lists and maps are specified using separate arguments, avoiding
the need for additional escaping of their separator and reusing the
existing command line spliting logic instead.
As discussed on #2087, this should make it much easier to work with
list options, and make the general option system feel cleaner.
Diffstat (limited to 'src/option.hh')
| -rw-r--r-- | src/option.hh | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/option.hh b/src/option.hh index f4aafe3a..19ca709f 100644 --- a/src/option.hh +++ b/src/option.hh @@ -16,6 +16,33 @@ inline String option_to_string(int opt); inline String option_to_string(size_t opt); inline String option_to_string(bool opt); +// Default fallback to single value functions +template<typename T> +decltype(option_from_string(Meta::Type<T>{}, StringView{})) +option_from_strings(Meta::Type<T>, ConstArrayView<String> strs) +{ + if (strs.size() != 1) + throw runtime_error("expected a single value for option"); + return option_from_string(Meta::Type<T>{}, strs[0]); +} + +template<typename T> +Vector<decltype(option_to_string(std::declval<T>()))> +option_to_strings(const T& opt) +{ + return Vector<String>{option_to_string(opt)}; +} + +template<typename T> +decltype(option_add(std::declval<T>(), std::declval<String>())) +option_add_from_strings(T& opt, ConstArrayView<String> strs) +{ + if (strs.size() != 1) + throw runtime_error("expected a single value for option"); + return option_add(opt, strs[0]); +} + + template<typename P, typename T> struct PrefixedList { |
