-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#287): Added spacing to command help
- Loading branch information
1 parent
97e8154
commit 4fb5a29
Showing
1 changed file
with
18 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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""") | ||
|