From 32aa580984d846fd8c3df46beebe1ed58c09d27f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 17 Feb 2023 20:31:47 +0530 Subject: [PATCH] Store parsed multi option values on the config object --- kittens/ssh/options/definition.py | 4 ++-- kitty/conf/generate.py | 11 +++++------ tools/cmd/ssh/config.go | 23 +++++++++++++++++++++++ 3 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 tools/cmd/ssh/config.go diff --git a/kittens/ssh/options/definition.py b/kittens/ssh/options/definition.py index bc9684ca4..a0186af13 100644 --- a/kittens/ssh/options/definition.py +++ b/kittens/ssh/options/definition.py @@ -44,7 +44,7 @@ The location on the remote host where the files needed for this kitten are installed. Relative paths are resolved with respect to :code:`$HOME`. ''') -opt('+copy', '', add_to_default=False, long_text=f''' +opt('+copy', '', add_to_default=False, ctype='CopyInstruction', long_text=f''' {copy_message} For example:: copy .vimrc .zshrc .config/some-dir @@ -80,7 +80,7 @@ The login shell to execute on the remote host. By default, the remote user account's login shell is used. ''') -opt('+env', '', add_to_default=False, long_text=''' +opt('+env', '', add_to_default=False, ctype='EnvInstruction', long_text=''' Specify the environment variables to be set on the remote host. Using the name with an equal sign (e.g. :code:`env VAR=`) will set it to the empty string. Specifying only the name (e.g. :code:`env VAR`) will remove the variable from diff --git a/kitty/conf/generate.py b/kitty/conf/generate.py index b93f131f2..460cc7aae 100644 --- a/kitty/conf/generate.py +++ b/kitty/conf/generate.py @@ -442,7 +442,9 @@ def write_output(loc: str, defn: Definition) -> None: f.write(f'{c}\n') -def go_type_data(parser_func: ParserFuncType, type_defs: List[str]) -> Tuple[str, str]: +def go_type_data(parser_func: ParserFuncType, ctype: str) -> Tuple[str, str]: + if ctype: + return f'*{ctype}', f'New{ctype}(val)' p = parser_func.__name__ if p == 'int': return 'int64', 'strconv.ParseInt(val, 10, 64)' @@ -465,11 +467,10 @@ def gen_go_code(defn: Definition) -> str: go_parsers = {} defaults = {} multiopts = {''} - type_defs = [''] for option in sorted(defn.iter_all_options(), key=lambda a: natural_keys(a.name)): name = option.name.capitalize() if isinstance(option, MultiOption): - go_types[name], go_parsers[name] = go_type_data(option.parser_func, type_defs) + go_types[name], go_parsers[name] = go_type_data(option.parser_func, option.ctype) multiopts.add(name) else: defaults[name] = option.parser_func(option.defval_as_string) @@ -478,12 +479,10 @@ def gen_go_code(defn: Definition) -> str: go_types[name] = f'{name}_Choice_Type' go_parsers[name] = f'Parse_{name}(val)' continue - go_types[name], go_parsers[name] = go_type_data(option.parser_func, type_defs) + go_types[name], go_parsers[name] = go_type_data(option.parser_func, option.ctype) for oname in choices: a(f'type {go_types[oname]} int') - for td in type_defs: - a(td) a('type Config struct {') for name, gotype in go_types.items(): if name in multiopts: diff --git a/tools/cmd/ssh/config.go b/tools/cmd/ssh/config.go new file mode 100644 index 000000000..58abd406a --- /dev/null +++ b/tools/cmd/ssh/config.go @@ -0,0 +1,23 @@ +// License: GPLv3 Copyright: 2023, Kovid Goyal, + +package ssh + +import ( + "fmt" +) + +var _ = fmt.Print + +type EnvInstruction struct { +} + +type CopyInstruction struct { +} + +func NewEnvInstruction(spec string) (ei *EnvInstruction, err error) { + return +} + +func NewCopyInstruction(spec string) (ci *CopyInstruction, err error) { + return +}