2024-07-05 22:16:41 +00:00
|
|
|
from .commands import commands
|
2024-07-02 16:09:56 +00:00
|
|
|
|
2024-07-03 18:36:22 +00:00
|
|
|
def display_help(extra_args):
|
2024-07-05 14:05:35 +00:00
|
|
|
"""
|
|
|
|
Display help dialogues for each command
|
|
|
|
"""
|
2024-07-03 18:36:22 +00:00
|
|
|
if not extra_args:
|
|
|
|
print(f"{commands['help'].description}")
|
|
|
|
return
|
|
|
|
if len(extra_args) > 1:
|
|
|
|
raise ValueError("Invalid arguments for help command")
|
|
|
|
if extra_args[0] not in commands:
|
|
|
|
raise ValueError("Unknown command")
|
|
|
|
print(f"{commands[extra_args[0]].description}")
|
2024-07-02 16:09:56 +00:00
|
|
|
|
2024-07-03 18:36:22 +00:00
|
|
|
def run(command, args):
|
2024-07-05 14:05:35 +00:00
|
|
|
"""
|
|
|
|
Runs a given command with the provided args
|
|
|
|
Alsso automatically maps the given command string to the correct Command class
|
|
|
|
"""
|
2024-07-03 18:36:22 +00:00
|
|
|
if command not in commands:
|
|
|
|
raise ValueError("Invalid Command")
|
2024-07-02 19:45:56 +00:00
|
|
|
|
2024-07-03 18:36:22 +00:00
|
|
|
c = commands[command]
|
|
|
|
|
|
|
|
if args and c.args > len(args):
|
|
|
|
raise ValueError("Too many arguments")
|
|
|
|
if args and c.args < len(args) and not c.optional:
|
|
|
|
raise ValueError("Missing arguments")
|
|
|
|
|
|
|
|
if command == "help":
|
|
|
|
display_help(args)
|
|
|
|
return
|
|
|
|
|
2024-07-05 22:16:41 +00:00
|
|
|
c.func(args)
|