Skip to content

Commit

Permalink
In 'apio -h' help text, splitted the 'project' group into 'build' and…
Browse files Browse the repository at this point in the history
… 'verification' groups. The goal is to simplify the initial user experience (a small build group) and to emphasize the veriication aspect to more experience users. No change in command behavior.

Also, simplified the grouping code.
  • Loading branch information
zapta committed Oct 20, 2024
1 parent 5e464b4 commit b4bf6e7
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 48 deletions.
100 changes: 54 additions & 46 deletions apio/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,40 @@
import click
from apio import util

# -- Maps group title to command names. Controls how the 'apio -h' help
# -- information is printed. Should include all commands and without
# -- duplicates.
COMMAND_GROUPS = {
"Build commands": [
"build",
"upload",
"clean",
],
"Verification commands": [
"verify",
"lint",
"sim",
"test",
"time",
"report",
"graph",
],
"Setup commands": [
"create",
"modify",
"drivers",
"install",
"uninstall",
],
"Utility commands": [
"boards",
"examples",
"raw",
"system",
"upgrade",
],
}


def select_commands_help(
command_lines: List[str], command_names: List[str]
Expand Down Expand Up @@ -70,56 +104,30 @@ def reformat_apio_help(original_help: str) -> str:
index += 1 # Skip the Commands: line.
command_lines = help_lines[index:]

# -- Select project commands by the order they are listed here.
project_help = select_commands_help(
command_lines,
[
"build",
"clean",
"verify",
"sim",
"test",
"lint",
"upload",
"time",
"report",
"graph",
],
)
# -- Select setup commands by the order they are listed here.
setup_help = select_commands_help(
command_lines,
["create", "modify", "drivers", "install", "uninstall"],
)

# -- Select utility commands by the order they are listed here.
utility_help = select_commands_help(
command_lines,
["boards", "examples", "raw", "system", "upgrade"],
)

# -- Sanity check, in case we mispelled or ommited a command name.
num_selected = len(project_help) + len(setup_help) + len(utility_help)
assert len(command_lines) == num_selected

# -- Header
result = []
result.extend(header_lines)

# -- Project commands:
result.append("Project commands:")
result.extend(project_help)
result.append("")

# -- Setup commands:
result.append("Setup commands:")
result.extend(setup_help)
result.append("")

# -- Print utility commands:
result.append("Utility commands:")
result.extend(utility_help)
result.append("")
# -- Print the help of the command groups while verifying that there
# -- are no missing or duplicate commands.
reported_commands = set()
for group_title, command_names in COMMAND_GROUPS.items():
# -- Assert no duplicates inter and intra groups.
assert len(command_names) == len(set(command_names))
assert reported_commands.isdisjoint(command_names)
reported_commands.update(command_names)
# -- Select the help lines of the commands in this group.
group_help = select_commands_help(command_lines, command_names)
# -- Append the group title and command lines.
result.append(f"{group_title}:")
result.extend(group_help)
result.append("")

# -- If this assertion fails, for a missing command in the groups
# -- definitions.
assert len(command_lines) == len(
reported_commands
), f"{command_lines=}, {len(reported_commands)=}"

return "\n".join(result)

Expand Down
2 changes: 1 addition & 1 deletion apio/commands/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

@click.command(
"clean",
short_help="Clean the apio generated files.",
short_help="Delete the apio generated files.",
help=HELP,
cls=cmd_util.ApioCommand,
)
Expand Down
2 changes: 1 addition & 1 deletion apio/commands/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

@click.command(
"verify",
short_help="Verify project's verilog code.",
short_help="Verify the verilog code.",
help=HELP,
cls=cmd_util.ApioCommand,
)
Expand Down

0 comments on commit b4bf6e7

Please sign in to comment.