A bit of work on the command line
This commit is contained in:
parent
0ec287c977
commit
e733694f2d
31
shlax/cli.py
31
shlax/cli.py
@ -20,22 +20,35 @@ class Group(cli2.Group):
|
|||||||
self.cmdclass = Command
|
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):
|
class Command(cli2.Command):
|
||||||
def call(self, *args, **kwargs):
|
def setargs(self):
|
||||||
return self.shlax_target(self.target)
|
super().setargs()
|
||||||
|
self['target'] = TargetArgument(
|
||||||
|
self,
|
||||||
|
self.sig.parameters['target'],
|
||||||
|
)
|
||||||
|
if 'actions' in self:
|
||||||
|
del self['actions']
|
||||||
|
|
||||||
def __call__(self, *argv):
|
def __call__(self, *argv):
|
||||||
from shlax.targets.base import Target
|
super().__call__(*argv)
|
||||||
self.shlax_target = Target()
|
self['target'].value.output.results(self['target'].value)
|
||||||
result = super().__call__(*argv)
|
|
||||||
self.shlax_target.output.results(self.shlax_target)
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
class ActionCommand(Command):
|
class ActionCommand(cli2.Command):
|
||||||
def call(self, *args, **kwargs):
|
def call(self, *args, **kwargs):
|
||||||
self.target = self.target(*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):
|
class ConsoleScript(Group):
|
||||||
|
|||||||
@ -18,6 +18,9 @@ class Target:
|
|||||||
self.parent = None
|
self.parent = None
|
||||||
self.root = root or os.getcwd()
|
self.root = root or os.getcwd()
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return 'localhost'
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def parent(self):
|
def parent(self):
|
||||||
return self._parent or Target()
|
return self._parent or Target()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user