29 lines
786 B
Python
29 lines
786 B
Python
from ..commands.factory import commands
|
|
|
|
def display_help(extra_args):
|
|
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}")
|
|
|
|
def run(command, args):
|
|
if command not in commands:
|
|
raise ValueError("Invalid Command")
|
|
|
|
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
|
|
|
|
c.binding(args)
|