Skip to content

Commit

Permalink
feat: sort commands list
Browse files Browse the repository at this point in the history
and warn about duplicates
  • Loading branch information
ThisAMJ committed Sep 9, 2024
1 parent 2df2774 commit 8b43a02
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
<input type="text" id="command-search" onkeyup="searchCommands()" placeholder="Search commands...">
Expand All @@ -77,16 +85,22 @@ def generate_command_table():
</tr>
"""

commands = []
with open("commands.csv", newline="") as f:
reader = csv.DictReader(f)
for row in reader:
out += f"""
<tr>
<td><code>{row["Command"]}</code></td>
<td>{row["Type"]}</td>
<td>{row["Allowed Values"]}</td>
</tr>
"""
commands.append(row)

last = ''
for cmd in sorted(commands, key=sort_command_func):
if cmd['Command'] == last:
print(f"Duplicate command: {cmd['Command']}")
out += "<tr>"
out += f"<td>{cmd['Command']}</td>"
out += f"<td>{cmd['Type']}</td>"
out += f"<td>{cmd['Allowed Values']}</td>"
out += "</tr>"
last = cmd['Command']

out += "</table>"
return out
Expand Down

0 comments on commit 8b43a02

Please sign in to comment.