Automap a bunch of json fields from identically named options
This commit is contained in:
+9
-4
@@ -49,8 +49,7 @@ go_getter_map = {
|
||||
|
||||
class GoOption:
|
||||
|
||||
def __init__(self, cmd_name: str, x: OptionDict) -> None:
|
||||
self.cmd_name = cmd_name
|
||||
def __init__(self, x: OptionDict) -> None:
|
||||
flags = sorted(x['aliases'], key=len)
|
||||
short = ''
|
||||
self.aliases = []
|
||||
@@ -107,13 +106,19 @@ class GoOption:
|
||||
else:
|
||||
raise TypeError(f'Unknown type of CLI option: {self.type} for {self.long}')
|
||||
|
||||
def set_flag_value(self, cmd: str = 'cmd') -> str:
|
||||
def set_flag_value(self, struct_name: str, cmd: str = 'cmd') -> str:
|
||||
func = go_getter_map[self.type]
|
||||
ans = f'{self.go_var_name}_temp, err := {cmd}.Flags().{func}("{self.long}")\n if err != nil {{ return err }}'
|
||||
ans += f'\noptions_{self.cmd_name}.{self.go_var_name} = {self.go_var_name}_temp'
|
||||
ans += f'\n{struct_name}.{self.go_var_name} = {self.go_var_name}_temp'
|
||||
return ans
|
||||
|
||||
|
||||
def go_options_for_seq(seq: 'OptionSpecSeq') -> Iterator[GoOption]:
|
||||
for x in seq:
|
||||
if not isinstance(x, str):
|
||||
yield GoOption(x)
|
||||
|
||||
|
||||
CONFIG_HELP = '''\
|
||||
Specify a path to the configuration file(s) to use. All configuration files are
|
||||
merged onto the builtin :file:`{conf_name}.conf`, overriding the builtin values.
|
||||
|
||||
@@ -17,7 +17,6 @@ class CloseTab(RemoteCommand):
|
||||
|
||||
protocol_spec = __doc__ = '''
|
||||
match/str: Which tab to close
|
||||
no_response/bool: Boolean indicating whether to wait for a response
|
||||
self/bool: Boolean indicating whether to close the tab of the window the command is run in
|
||||
ignore_no_match/bool: Boolean indicating whether no matches should be ignored or return an error
|
||||
'''
|
||||
|
||||
@@ -16,7 +16,6 @@ if TYPE_CHECKING:
|
||||
class CloseWindow(RemoteCommand):
|
||||
protocol_spec = __doc__ = '''
|
||||
match/str: Which window to close
|
||||
no_response/bool: Boolean indicating whether to wait for a response
|
||||
self/bool: Boolean indicating whether to close the window the command is run in
|
||||
ignore_no_match/bool: Boolean indicating whether no matches should be ignored or return an error
|
||||
'''
|
||||
|
||||
@@ -60,6 +60,7 @@ screen edges).
|
||||
|
||||
|
||||
--clear-selection
|
||||
type=bool-set
|
||||
Clear the selection in the matched window, if any.
|
||||
|
||||
|
||||
|
||||
@@ -42,7 +42,6 @@ class Launch(RemoteCommand):
|
||||
stdin_add_formatting/bool: Boolean indicating whether to add formatting codes to stdin
|
||||
stdin_add_line_wrap_markers/bool: Boolean indicating whether to add line wrap markers to stdin
|
||||
spacing/list.str: A list of spacing specifications, see the docs for the set-spacing command
|
||||
no_response/bool: Boolean indicating whether to send back the window id
|
||||
marker/str: Specification for marker for new window, for example: "text 1 ERROR"
|
||||
logo/str: Path to window logo
|
||||
logo_position/str: Window logo position as string or empty string to use default
|
||||
|
||||
@@ -23,7 +23,6 @@ class NewWindow(RemoteCommand):
|
||||
window_type/choices.kitty.os: One of :code:`kitty` or :code:`os`
|
||||
new_tab/bool: Boolean indicating whether to open a new tab
|
||||
tab_title/str: Title for the new tab
|
||||
no_response/bool: Boolean indicating whether to send back the window id
|
||||
'''
|
||||
|
||||
short_desc = 'Open new window'
|
||||
|
||||
@@ -21,7 +21,6 @@ class ScrollWindow(RemoteCommand):
|
||||
And the second item being either 'p' for pages or 'l' for lines or 'u'
|
||||
for unscrolling by lines.
|
||||
match/str: The window to scroll
|
||||
no_response/bool: Boolean indicating whether to wait for a response
|
||||
'''
|
||||
|
||||
short_desc = 'Scroll the specified windows'
|
||||
|
||||
@@ -17,7 +17,6 @@ class SignalChild(RemoteCommand):
|
||||
protocol_spec = __doc__ = '''
|
||||
signals/list.str: The signals, a list of names, such as :code:`SIGTERM`, :code:`SIGKILL`, :code:`SIGUSR1`, etc.
|
||||
match/str: Which windows to send the signals to
|
||||
no_response/bool: Boolean indicating whether to wait for a response
|
||||
'''
|
||||
|
||||
short_desc = 'Send a signal to the foreground process in the specified windows'
|
||||
|
||||
Reference in New Issue
Block a user