Skip to content

Commit

Permalink
feat(#287): Added spacing to command help
Browse files Browse the repository at this point in the history
  • Loading branch information
lxgr-linux committed Jul 13, 2024
1 parent 97e8154 commit 4fb5a29
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions util/command/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,34 @@ def __init__(
self.commands = commands if commands is not None else []
self.usage = usage

@staticmethod
def __line_setter(lines: list[tuple[str, str]], line_spaces: int):
return "\n".join(
f"\t{line[0]}{" " * (line_spaces - len(line[0]))}{line[1]}" for line
in lines
)

def __print_help(self, ex: str):
option_lines: list[tuple[str, str]] = [(command.name, command.desc) for
command in self.commands]
flag_lines: list[tuple[str, str]] = [
("|".join(flag.aliases), flag.desc) for flag in self.flags]

line_spaces = sorted([
len(i[0]) for i in option_lines + flag_lines
])[-1] + 8

print(f"""{self.name} -- {self.desc}
Usage:
{ex}{f" {self.usage}" if self.usage else ""} <flags>
{f"""
Options:
{"\n".join(f"\t{command.name}\t\t{command.desc}" for command in self.commands)}
{self.__line_setter(option_lines, line_spaces)}
""" if self.commands else ""}
{f"""
Flags:
{"\n".join(f"\t{"|".join(flag.aliases)}\t\t{flag.desc}" for flag in self.flags)}
{self.__line_setter(flag_lines, line_spaces)}
""" if self.flags else ""}
{f"\n{self.additional_info}\n" if self.additional_info else ""}
Copyright (c) lxgr-linux <[email protected]> 2024""")
Expand Down

0 comments on commit 4fb5a29

Please sign in to comment.