diff --git a/gen-go-code.py b/gen-go-code.py index 1b737859e..0a88d8594 100755 --- a/gen-go-code.py +++ b/gen-go-code.py @@ -4,6 +4,7 @@ import io import json import os +import subprocess import sys from contextlib import contextmanager, suppress from functools import lru_cache @@ -295,7 +296,7 @@ var DocTitleMap = map[string]string{serialize_go_dict(ref_map['doc'])} # Boilerplate {{{ @contextmanager -def replace_if_needed(path: str) -> Iterator[io.StringIO]: +def replace_if_needed(path: str, show_diff: bool = False) -> Iterator[io.StringIO]: buf = io.StringIO() yield buf orig = '' @@ -305,6 +306,11 @@ def replace_if_needed(path: str) -> Iterator[io.StringIO]: new = f'// Code generated by {os.path.basename(__file__)}; DO NOT EDIT.\n\n' + new if orig != new: changed.append(path) + if show_diff: + with open(path + '.new', 'w') as f: + f.write(new) + subprocess.run(['diff', '-Naurp', path, f.name], stdout=open('/dev/tty', 'w')) + os.remove(f.name) with open(path, 'w') as f: f.write(new) diff --git a/kitty/cli.py b/kitty/cli.py index dc51de49b..45d502a9a 100644 --- a/kitty/cli.py +++ b/kitty/cli.py @@ -148,7 +148,7 @@ class GoOption: def as_option(self, cmd_name: str = 'cmd', depth: int = 0, group: str = '') -> str: add = f'AddToGroup("{serialize_as_go_string(group)}", ' if group else 'Add(' - aliases = ' '.join(self.obj_dict['aliases']) + aliases = ' '.join(sorted(self.obj_dict['aliases'])) ans = f'''{cmd_name}.{add}cli.OptionSpec{{ Name: "{serialize_as_go_string(aliases)}", Type: "{self.type}",