From 8b43a02750e15b5ddceb80c01bc5c7d3d5e22e33 Mon Sep 17 00:00:00 2001 From: Jesse <69196954+ThisAMJ@users.noreply.github.com> Date: Mon, 9 Sep 2024 19:28:04 +1000 Subject: [PATCH] feat: sort commands list and warn about duplicates --- generate.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/generate.py b/generate.py index 50e5cd6..e22c5f3 100755 --- a/generate.py +++ b/generate.py @@ -66,6 +66,14 @@ def generate_nav(sections): return out +def sort_command_func(cmd): + command = cmd["Command"] + if command.startswith('-'): + return '0' + command[1:] + '1' + elif command.startswith('+'): + return '0' + command[1:] + '0' + return '1' + command + '2' + def generate_command_table(): out = """ @@ -77,16 +85,22 @@ def generate_command_table(): """ + commands = [] with open("commands.csv", newline="") as f: reader = csv.DictReader(f) for row in reader: - out += f""" - - {row["Command"]} - {row["Type"]} - {row["Allowed Values"]} - - """ + commands.append(row) + + last = '' + for cmd in sorted(commands, key=sort_command_func): + if cmd['Command'] == last: + print(f"Duplicate command: {cmd['Command']}") + out += "" + out += f"{cmd['Command']}" + out += f"{cmd['Type']}" + out += f"{cmd['Allowed Values']}" + out += "" + last = cmd['Command'] out += "" return out