mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-10-08 06:03:56 +00:00
Add type checking for the various CLI options objects
This commit is contained in:
parent
0f4e7921ee
commit
f05890719d
27 changed files with 487 additions and 157 deletions
|
|
@ -12,7 +12,7 @@ from kitty.conf.definition import config_lines
|
|||
from kitty.constants import config_dir
|
||||
from kitty.rgb import color_as_sgr
|
||||
|
||||
from .config_data import type_map, all_options
|
||||
from .config_data import type_convert, all_options
|
||||
|
||||
defaults = None
|
||||
|
||||
|
|
@ -89,7 +89,7 @@ def parse_config(lines, check_keys=True):
|
|||
parse_config_base(
|
||||
lines,
|
||||
defaults,
|
||||
type_map,
|
||||
type_convert,
|
||||
special_handling,
|
||||
ans,
|
||||
check_keys=check_keys
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@
|
|||
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
|
||||
from functools import partial
|
||||
# Utils {{{
|
||||
from functools import partial
|
||||
from gettext import gettext as _
|
||||
from typing import Dict, Union
|
||||
from typing import Any, Dict, Union
|
||||
|
||||
from kitty.conf.definition import Option, Shortcut, option_func
|
||||
from kitty.conf.utils import positive_int, python_string, to_color
|
||||
|
|
@ -120,4 +120,9 @@ k('prev_match', '<', 'scroll_to prev-match', _('Scroll to previous search match'
|
|||
k('search_forward_simple', 'f', 'start_search substring forward', _('Search forward (no regex)'))
|
||||
k('search_backward_simple', 'b', 'start_search substring backward', _('Search backward (no regex)'))
|
||||
|
||||
type_map = {o.name: o.option_type for o in all_options.values() if isinstance(o, Option)}
|
||||
|
||||
def type_convert(name: str, val: Any) -> Any:
|
||||
o = all_options.get(name)
|
||||
if isinstance(o, Option):
|
||||
val = o.option_type(val)
|
||||
return val
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ from functools import partial
|
|||
from gettext import gettext as _
|
||||
|
||||
from kitty.cli import CONFIG_HELP, parse_args
|
||||
from kitty.cli_stub import DiffCLIOptions
|
||||
from kitty.constants import appname
|
||||
from kitty.fast_data_types import wcswidth
|
||||
from kitty.key_encoding import RELEASE, enter_key, key_defs as K
|
||||
|
|
@ -542,7 +543,7 @@ def get_remote_file(path):
|
|||
|
||||
def main(args):
|
||||
warnings.showwarning = showwarning
|
||||
args, items = parse_args(args[1:], OPTIONS, usage, help_text, 'kitty +kitten diff')
|
||||
args, items = parse_args(args[1:], OPTIONS, usage, help_text, 'kitty +kitten diff', result_class=DiffCLIOptions)
|
||||
if len(items) != 2:
|
||||
raise SystemExit('You must specify exactly two files/directories to compare')
|
||||
left, right = items
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue