This commit is contained in:
Kovid Goyal
2025-06-19 11:58:02 +05:30
parent 9de6bfbbd7
commit c7fcd44ecf

View File

@@ -650,7 +650,10 @@ def gen_go_code(defn: Definition) -> str:
a(f'default: return ans, fmt.Errorf("%#v is not a valid value for %s. Valid values are: %s", val, "{c}", "{vals}")')
a('}''}')
has_parsers = bool(go_parsers or keyboard_shortcuts)
a('func (c *Config) Parse(key, val string) (err error) {')
if has_parsers:
if go_parsers:
a('switch key {')
a('default: return fmt.Errorf("Unknown configuration key: %#v", key)')
for oname, pname in go_parsers.items():
@@ -674,6 +677,9 @@ def gen_go_code(defn: Definition) -> str:
a('c.KeyboardShortcuts = append(c.KeyboardShortcuts, tempsc)')
a('}')
a('return}')
else:
a('return fmt.Errorf("Unknown configuration key: %#v", key)')
a('}')
return '\n'.join(lines)