dockge-cli/dockge_cli/client/run.py
Firq a99b81b0c7
All checks were successful
/ pylint (push) Successful in 11s
/ mypy (push) Successful in 13s
Pylint settings
2024-07-05 16:05:35 +02:00

36 lines
996 B
Python

from .commandprovider.factory import commands
def display_help(extra_args):
"""
Display help dialogues for each command
"""
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):
"""
Runs a given command with the provided args
Alsso automatically maps the given command string to the correct Command class
"""
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.bind(args)