From 62299da7c1f4bfea9c76ab95856a9afc472bbb21 Mon Sep 17 00:00:00 2001 From: jpic Date: Sun, 31 May 2020 13:21:09 +0200 Subject: [PATCH] A bit of work on the command line --- shlax/cli.py | 31 ++++++++++++++++++++++--------- shlax/targets/base.py | 3 +++ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/shlax/cli.py b/shlax/cli.py index feae747..a40b741 100644 --- a/shlax/cli.py +++ b/shlax/cli.py @@ -20,22 +20,35 @@ class Group(cli2.Group): self.cmdclass = Command +class TargetArgument(cli2.Argument): + """DSN of the target to execute on, localhost by default, TBI""" + + def __init__(self, cmd, param, doc=None, color=None, default=None): + from shlax.targets.base import Target + super().__init__(cmd, param, doc=self.__doc__, default=Target()) + self.alias = ['target', 't'] + + class Command(cli2.Command): - def call(self, *args, **kwargs): - return self.shlax_target(self.target) + def setargs(self): + super().setargs() + self['target'] = TargetArgument( + self, + self.sig.parameters['target'], + ) + if 'actions' in self: + del self['actions'] def __call__(self, *argv): - from shlax.targets.base import Target - self.shlax_target = Target() - result = super().__call__(*argv) - self.shlax_target.output.results(self.shlax_target) - return result + super().__call__(*argv) + self['target'].value.output.results(self['target'].value) -class ActionCommand(Command): +class ActionCommand(cli2.Command): def call(self, *args, **kwargs): self.target = self.target(*args, **kwargs) - return super().call(*args, **kwargs) + from shlax.targets.base import Target + return super().call(Target()) class ConsoleScript(Group): diff --git a/shlax/targets/base.py b/shlax/targets/base.py index 04f5306..0b555b3 100644 --- a/shlax/targets/base.py +++ b/shlax/targets/base.py @@ -18,6 +18,9 @@ class Target: self.parent = None self.root = root or os.getcwd() + def __str__(self): + return 'localhost' + @property def parent(self): return self._parent or Target()