From 409b6253099cb851a18020e8c5882cba039b02c0 Mon Sep 17 00:00:00 2001 From: jpic Date: Wed, 12 Feb 2020 12:01:47 +0100 Subject: [PATCH] Remove Run --- podctl/console_script.py | 20 +++++++++++++++++++- podctl/container.py | 6 ------ podctl/pod.py | 3 +-- podctl/run.py | 5 ----- podctl/script.py | 3 ++- 5 files changed, 22 insertions(+), 15 deletions(-) delete mode 100644 podctl/run.py diff --git a/podctl/console_script.py b/podctl/console_script.py index 58bd702..da94f5f 100644 --- a/podctl/console_script.py +++ b/podctl/console_script.py @@ -15,13 +15,31 @@ from .service import Service class ConsoleScript(cli2.ConsoleScript): + class Parser(cli2.Parser): + def parse(self): + super().parse() + if str(self.command) == 'help': + return + + self.forward_args = [] + + found_dash = False + for arg in self.argv: + if arg == '--': + found_dash = True + if not found_dash: + continue + self.forward_args.append(arg) + + self.funckwargs['cmd'] = self.forward_args + def __call__(self, *args, **kwargs): import inspect from podctl.podfile import Podfile self.podfile = Podfile.factory(os.getenv('PODFILE', 'pod.py')) for name, script in self.podfile.pod.scripts.items(): cb = self.podfile.pod.script(name) - cb.__doc__ = inspect.getdoc(script) + cb.__doc__ = inspect.getdoc(script) or script.doc self[name] = cli2.Callable(name, cb) return super().__call__(*args, **kwargs) diff --git a/podctl/container.py b/podctl/container.py index a1ac82f..ce5b775 100644 --- a/podctl/container.py +++ b/podctl/container.py @@ -1,9 +1,3 @@ -import asyncio -import os -import shlex - -from .build import Build -from .run import Run from .visitable import Visitable diff --git a/podctl/pod.py b/podctl/pod.py index 82400c9..877d175 100644 --- a/podctl/pod.py +++ b/podctl/pod.py @@ -4,7 +4,6 @@ import os from .build import Build from .container import Container -from .run import Run from .script import Script from .visitable import Visitable @@ -12,7 +11,7 @@ from .visitable import Visitable class Pod(Visitable): default_scripts = dict( build=Build(), - run=Run(), + run=Script('run', 'Run a container command'), ) @property diff --git a/podctl/run.py b/podctl/run.py deleted file mode 100644 index de826f1..0000000 --- a/podctl/run.py +++ /dev/null @@ -1,5 +0,0 @@ -from .script import Script - - -class Run(Script): - """Run a container""" diff --git a/podctl/script.py b/podctl/script.py index 0dba771..da78475 100644 --- a/podctl/script.py +++ b/podctl/script.py @@ -4,8 +4,9 @@ from .proc import Proc class Script: - def __init__(self, name=None): + def __init__(self, name=None, doc=None): self.name = name or type(self).__name__.lower() + self.doc = doc or 'Custom script' async def exec(self, *args, **kwargs): """Execute a command on the host."""