Dont parse default values
This commit is contained in:
parent
5822bb23f0
commit
1470b11024
@ -10,9 +10,6 @@ from kitty.conf.utils import load_config as _load_config
|
|||||||
from kitty.conf.utils import parse_config_base, resolve_config
|
from kitty.conf.utils import parse_config_base, resolve_config
|
||||||
from kitty.constants import config_dir
|
from kitty.constants import config_dir
|
||||||
|
|
||||||
from .options.types import Options as SSHOptions
|
|
||||||
from .options.types import defaults
|
|
||||||
|
|
||||||
SYSTEM_CONF = '/etc/xdg/kitty/ssh.conf'
|
SYSTEM_CONF = '/etc/xdg/kitty/ssh.conf'
|
||||||
defconf = os.path.join(config_dir, 'ssh.conf')
|
defconf = os.path.join(config_dir, 'ssh.conf')
|
||||||
|
|
||||||
@ -27,7 +24,7 @@ def host_matches(mpat: str, hostname: str, username: str) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def load_config(*paths: str, overrides: Optional[Iterable[str]] = None, hostname: str = '!', username: str = '') -> SSHOptions:
|
def load_config(*paths: str, overrides: Optional[Iterable[str]] = None, hostname: str = '!', username: str = '') -> 'SSHOptions':
|
||||||
from .options.parse import create_result_dict, merge_result_dicts, parse_conf_item
|
from .options.parse import create_result_dict, merge_result_dicts, parse_conf_item
|
||||||
from .options.utils import first_seen_positions, get_per_hosts_dict, init_results_dict
|
from .options.utils import first_seen_positions, get_per_hosts_dict, init_results_dict
|
||||||
|
|
||||||
@ -65,6 +62,6 @@ def load_config(*paths: str, overrides: Optional[Iterable[str]] = None, hostname
|
|||||||
return SSHOptions(final_dict)
|
return SSHOptions(final_dict)
|
||||||
|
|
||||||
|
|
||||||
def init_config(hostname: str, username: str, overrides: Optional[Iterable[str]] = None) -> SSHOptions:
|
def init_config(hostname: str, username: str, overrides: Optional[Iterable[str]] = None) -> 'SSHOptions':
|
||||||
config = tuple(resolve_config(SYSTEM_CONF, defconf))
|
config = tuple(resolve_config(SYSTEM_CONF, defconf))
|
||||||
return load_config(*config, overrides=overrides, hostname=hostname, username=username)
|
return load_config(*config, overrides=overrides, hostname=hostname, username=username)
|
||||||
|
|||||||
@ -35,7 +35,6 @@ from ..tui.operations import RESTORE_PRIVATE_MODE_VALUES, SAVE_PRIVATE_MODE_VALU
|
|||||||
from ..tui.utils import kitty_opts, running_in_tmux
|
from ..tui.utils import kitty_opts, running_in_tmux
|
||||||
from .config import init_config
|
from .config import init_config
|
||||||
from .copy import CopyInstruction
|
from .copy import CopyInstruction
|
||||||
from .options.types import Options as SSHOptions
|
|
||||||
from .utils import create_shared_memory, get_ssh_cli, is_extra_arg, passthrough_args
|
from .utils import create_shared_memory, get_ssh_cli, is_extra_arg, passthrough_args
|
||||||
|
|
||||||
|
|
||||||
@ -101,7 +100,7 @@ def serialize_env(literal_env: Dict[str, str], env: Dict[str, str], base_env: Di
|
|||||||
return '\n'.join(lines).encode('utf-8')
|
return '\n'.join(lines).encode('utf-8')
|
||||||
|
|
||||||
|
|
||||||
def make_tarfile(ssh_opts: SSHOptions, base_env: Dict[str, str], compression: str = 'gz', literal_env: Dict[str, str] = {}) -> bytes:
|
def make_tarfile(ssh_opts: 'SSHOptions', base_env: Dict[str, str], compression: str = 'gz', literal_env: Dict[str, str] = {}) -> bytes:
|
||||||
|
|
||||||
def normalize_tarinfo(tarinfo: tarfile.TarInfo) -> tarfile.TarInfo:
|
def normalize_tarinfo(tarinfo: tarfile.TarInfo) -> tarfile.TarInfo:
|
||||||
tarinfo.uname = tarinfo.gname = ''
|
tarinfo.uname = tarinfo.gname = ''
|
||||||
@ -249,7 +248,7 @@ def prepare_exec_cmd(remote_args: Sequence[str], is_python: bool) -> str:
|
|||||||
return f"""unset KITTY_SHELL_INTEGRATION; exec "$login_shell" -c '{args}'"""
|
return f"""unset KITTY_SHELL_INTEGRATION; exec "$login_shell" -c '{args}'"""
|
||||||
|
|
||||||
|
|
||||||
def prepare_export_home_cmd(ssh_opts: SSHOptions, is_python: bool) -> str:
|
def prepare_export_home_cmd(ssh_opts: 'SSHOptions', is_python: bool) -> str:
|
||||||
home = ssh_opts.env.get('HOME')
|
home = ssh_opts.env.get('HOME')
|
||||||
if home == '_kitty_copy_env_var_':
|
if home == '_kitty_copy_env_var_':
|
||||||
home = os.environ.get('HOME')
|
home = os.environ.get('HOME')
|
||||||
@ -262,7 +261,7 @@ def prepare_export_home_cmd(ssh_opts: SSHOptions, is_python: bool) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def bootstrap_script(
|
def bootstrap_script(
|
||||||
ssh_opts: SSHOptions, script_type: str = 'sh', remote_args: Sequence[str] = (),
|
ssh_opts: 'SSHOptions', script_type: str = 'sh', remote_args: Sequence[str] = (),
|
||||||
test_script: str = '', request_id: Optional[str] = None, cli_hostname: str = '', cli_uname: str = '',
|
test_script: str = '', request_id: Optional[str] = None, cli_hostname: str = '', cli_uname: str = '',
|
||||||
request_data: bool = False, echo_on: bool = True, literal_env: Dict[str, str] = {}
|
request_data: bool = False, echo_on: bool = True, literal_env: Dict[str, str] = {}
|
||||||
) -> Tuple[str, Dict[str, str], str]:
|
) -> Tuple[str, Dict[str, str], str]:
|
||||||
@ -471,7 +470,7 @@ def wrap_bootstrap_script(sh_script: str, interpreter: str) -> List[str]:
|
|||||||
|
|
||||||
|
|
||||||
def get_remote_command(
|
def get_remote_command(
|
||||||
remote_args: List[str], ssh_opts: SSHOptions, cli_hostname: str = '', cli_uname: str = '',
|
remote_args: List[str], ssh_opts: 'SSHOptions', cli_hostname: str = '', cli_uname: str = '',
|
||||||
echo_on: bool = True, request_data: bool = False, literal_env: Dict[str, str] = {}
|
echo_on: bool = True, request_data: bool = False, literal_env: Dict[str, str] = {}
|
||||||
) -> Tuple[List[str], Dict[str, str], str]:
|
) -> Tuple[List[str], Dict[str, str], str]:
|
||||||
interpreter = ssh_opts.interpreter
|
interpreter = ssh_opts.interpreter
|
||||||
|
|||||||
@ -472,7 +472,7 @@ def gen_go_code(defn: Definition) -> str:
|
|||||||
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, type_defs)
|
||||||
multiopts.add(name)
|
multiopts.add(name)
|
||||||
else:
|
else:
|
||||||
defaults[name] = option.defval_as_string
|
defaults[name] = option.parser_func(option.defval_as_string)
|
||||||
if option.choices:
|
if option.choices:
|
||||||
choices[name] = option.choices
|
choices[name] = option.choices
|
||||||
go_types[name] = f'{name}_Choice_Type'
|
go_types[name] = f'{name}_Choice_Type'
|
||||||
@ -492,23 +492,26 @@ def gen_go_code(defn: Definition) -> str:
|
|||||||
a(f'{name} {gotype}')
|
a(f'{name} {gotype}')
|
||||||
a('}')
|
a('}')
|
||||||
|
|
||||||
a('func NewConfig() *Config {')
|
|
||||||
a('ans := Config{}')
|
|
||||||
a('var err error')
|
|
||||||
a('var val string')
|
|
||||||
for name, pname in go_parsers.items():
|
|
||||||
if name in multiopts:
|
|
||||||
a(f'ans.{name} = make([]{go_types[name]}, 0, 8)')
|
|
||||||
continue
|
|
||||||
a(f'val = `{defaults[name]}`')
|
|
||||||
a(f'ans.{name}, err = {pname}')
|
|
||||||
a('if err != nil { panic(err) }')
|
|
||||||
a('return &ans')
|
|
||||||
a('}')
|
|
||||||
|
|
||||||
def cval(x: str) -> str:
|
def cval(x: str) -> str:
|
||||||
return x.replace('-', '_')
|
return x.replace('-', '_')
|
||||||
|
|
||||||
|
a('func NewConfig() *Config {')
|
||||||
|
a('return &Config{')
|
||||||
|
for name, pname in go_parsers.items():
|
||||||
|
if name in multiopts:
|
||||||
|
continue
|
||||||
|
d = defaults[name]
|
||||||
|
if not d:
|
||||||
|
continue
|
||||||
|
if isinstance(d, str):
|
||||||
|
dval = f'{name}_{cval(d)}' if name in choices else f'`{d}`'
|
||||||
|
elif isinstance(d, bool):
|
||||||
|
dval = repr(d).lower()
|
||||||
|
else:
|
||||||
|
dval = repr(d)
|
||||||
|
a(f'{name}: {dval},')
|
||||||
|
a('}''}')
|
||||||
|
|
||||||
for oname, choice_vals in choices.items():
|
for oname, choice_vals in choices.items():
|
||||||
a('const (')
|
a('const (')
|
||||||
for i, c in enumerate(choice_vals):
|
for i, c in enumerate(choice_vals):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user