dockge-cli/dockge_cli/components/run.py
Firq 537a0d8015
All checks were successful
/ backend-pylint (push) Successful in 11s
/ build-artifacts (push) Successful in 10s
/ publish-artifacts (push) Successful in 8s
Rewrote using command factory
2024-07-03 20:36:22 +02:00

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)