From 01eeb1491366fbb012bcf07966c32aa8fa95dcf1 Mon Sep 17 00:00:00 2001 From: hl Date: Fri, 11 Apr 2025 02:47:18 +0800 Subject: [PATCH] update --- sort_known_hosts.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/sort_known_hosts.py b/sort_known_hosts.py index 9937501..dd396ab 100755 --- a/sort_known_hosts.py +++ b/sort_known_hosts.py @@ -19,8 +19,8 @@ class Entry(namedtuple('Entry', ['host', 'algorithm', 'hash'])): return f'{self.algorithm}{self.separator}{self.hash}' -def main(args): - filename: Path = getattr(args, 'known_hosts', Path()) +def run(args) -> None: + filename: Path = getattr(args, 'input', Path()) file_path = filename.resolve() if not file_path.is_file(): sys.exit(1) @@ -84,7 +84,7 @@ def main(args): wfp.writelines(output_lines) -if __name__ == '__main__': +def main() -> None: import argparse parser = argparse.ArgumentParser( @@ -92,12 +92,16 @@ if __name__ == '__main__': ) parser.add_argument( '-i', - '--known_hosts', + '--input', type=Path, - default=f"{os.path.expanduser('~')}/.ssh/known_hosts", - help='known_hosts file to read', + default=f'{os.path.expanduser("~")}/.ssh/known_hosts', + help='file to read', ) - parser.add_argument('-o', '--output', type=Path, help='output file to write') - parser.set_defaults(func=main) + parser.add_argument('-o', '--output', type=Path, help='file to write') + parser.set_defaults(func=run) args = parser.parse_args() args.func(args) + + +if __name__ == '__main__': + main()