mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-24 01:08:10 +02:00
...
This commit is contained in:
@@ -650,30 +650,36 @@ 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(f'default: return ans, fmt.Errorf("%#v is not a valid value for %s. Valid values are: %s", val, "{c}", "{vals}")')
|
||||||
a('}''}')
|
a('}''}')
|
||||||
|
|
||||||
|
has_parsers = bool(go_parsers or keyboard_shortcuts)
|
||||||
a('func (c *Config) Parse(key, val string) (err error) {')
|
a('func (c *Config) Parse(key, val string) (err error) {')
|
||||||
a('switch key {')
|
if has_parsers:
|
||||||
a('default: return fmt.Errorf("Unknown configuration key: %#v", key)')
|
if go_parsers:
|
||||||
for oname, pname in go_parsers.items():
|
a('switch key {')
|
||||||
ol = oname.lower()
|
a('default: return fmt.Errorf("Unknown configuration key: %#v", key)')
|
||||||
is_multiple = oname in multiopts
|
for oname, pname in go_parsers.items():
|
||||||
a(f'case "{ol}":')
|
ol = oname.lower()
|
||||||
if is_multiple:
|
is_multiple = oname in multiopts
|
||||||
a(f'var temp_val []{go_types[oname]}')
|
a(f'case "{ol}":')
|
||||||
else:
|
if is_multiple:
|
||||||
a(f'var temp_val {go_types[oname]}')
|
a(f'var temp_val []{go_types[oname]}')
|
||||||
a(f'temp_val, err = {pname}')
|
else:
|
||||||
a(f'if err != nil {{ return fmt.Errorf("Failed to parse {ol} = %#v with error: %w", val, err) }}')
|
a(f'var temp_val {go_types[oname]}')
|
||||||
if is_multiple:
|
a(f'temp_val, err = {pname}')
|
||||||
a(f'c.{oname} = append(c.{oname}, temp_val...)')
|
a(f'if err != nil {{ return fmt.Errorf("Failed to parse {ol} = %#v with error: %w", val, err) }}')
|
||||||
else:
|
if is_multiple:
|
||||||
a(f'c.{oname} = temp_val')
|
a(f'c.{oname} = append(c.{oname}, temp_val...)')
|
||||||
if keyboard_shortcuts:
|
else:
|
||||||
a('case "map":')
|
a(f'c.{oname} = temp_val')
|
||||||
a('tempsc, err := config.ParseMap(val)')
|
if keyboard_shortcuts:
|
||||||
a('if err != nil { return fmt.Errorf("Failed to parse map = %#v with error: %w", val, err) }')
|
a('case "map":')
|
||||||
a('c.KeyboardShortcuts = append(c.KeyboardShortcuts, tempsc)')
|
a('tempsc, err := config.ParseMap(val)')
|
||||||
a('}')
|
a('if err != nil { return fmt.Errorf("Failed to parse map = %#v with error: %w", val, err) }')
|
||||||
a('return}')
|
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)
|
return '\n'.join(lines)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user