Skip to content

Commit 8b43a02

Browse files
committed
feat: sort commands list
and warn about duplicates
1 parent 2df2774 commit 8b43a02

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

generate.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ def generate_nav(sections):
6666

6767
return out
6868

69+
def sort_command_func(cmd):
70+
command = cmd["Command"]
71+
if command.startswith('-'):
72+
return '0' + command[1:] + '1'
73+
elif command.startswith('+'):
74+
return '0' + command[1:] + '0'
75+
return '1' + command + '2'
76+
6977
def generate_command_table():
7078
out = """
7179
<input type="text" id="command-search" onkeyup="searchCommands()" placeholder="Search commands...">
@@ -77,16 +85,22 @@ def generate_command_table():
7785
</tr>
7886
"""
7987

88+
commands = []
8089
with open("commands.csv", newline="") as f:
8190
reader = csv.DictReader(f)
8291
for row in reader:
83-
out += f"""
84-
<tr>
85-
<td><code>{row["Command"]}</code></td>
86-
<td>{row["Type"]}</td>
87-
<td>{row["Allowed Values"]}</td>
88-
</tr>
89-
"""
92+
commands.append(row)
93+
94+
last = ''
95+
for cmd in sorted(commands, key=sort_command_func):
96+
if cmd['Command'] == last:
97+
print(f"Duplicate command: {cmd['Command']}")
98+
out += "<tr>"
99+
out += f"<td>{cmd['Command']}</td>"
100+
out += f"<td>{cmd['Type']}</td>"
101+
out += f"<td>{cmd['Allowed Values']}</td>"
102+
out += "</tr>"
103+
last = cmd['Command']
90104

91105
out += "</table>"
92106
return out

0 commit comments

Comments
 (0)