diff --git a/setup.py b/setup.py index b15babf..1eed12a 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name='shlax', versioning='dev', setup_requires='setupmeta', - install_requires=['cli2'], + install_requires=['cli2>=1.1.6'], extras_require=dict( full=[ 'pyyaml', diff --git a/shlax/cli.py b/shlax/cli.py index 0a0752c..8a1eb26 100644 --- a/shlax/cli.py +++ b/shlax/cli.py @@ -10,6 +10,7 @@ import asyncio import cli2 import copy import inspect +import importlib import glob import os import sys @@ -24,9 +25,32 @@ class ConsoleScript(cli2.ConsoleScript): self.shlaxfile = None shlaxfile = sys.argv.pop(1) if len(sys.argv) > 1 else '' if shlaxfile: - if os.path.exists(shlaxfile): - self.shlaxfile = Shlaxfile() - self.shlaxfile.parse(shlaxfile) + if not os.path.exists(shlaxfile): + try: # missing shlaxfile, what are we gonna do !! + mod = importlib.import_module('shlax.repo.' + shlaxfile) + except ImportError: + print('Could not find ' + shlaxfile) + self.exit_code = 1 + return + shlaxfile = mod.__file__ + + self.shlaxfile = Shlaxfile() + self.shlaxfile.parse(shlaxfile) + if len(self.shlaxfile.actions) == 1 and 'main' in self.shlaxfile.actions: + action = self.shlaxfile.actions['main'] + self._doc = inspect.getdoc(action) + for name, doc in self.shlaxfile.actions['main'].doc.items(): + self[name] = cli2.Callable( + name, + action.callable(), + options={ + k: cli2.Option(name=k, **v) + for k, v in action.options.items() + }, + color=getattr(action, 'color', cli2.YELLOW), + doc=doc, + ) + else: for name, action in self.shlaxfile.actions.items(): self[name] = cli2.Callable( name, @@ -37,24 +61,13 @@ class ConsoleScript(cli2.ConsoleScript): }, color=getattr(action, 'color', cli2.YELLOW), ) - else: - try: - mod = importlib.import_module('shlax.repo.' + shlaxfile) - except ImportError: - print('Could not find ' + shlaxfile) - self.exit_code = 1 - return else: from shlax import repo path = repo.__path__._path[0] for shlaxfile in glob.glob(os.path.join(path, '*.py')): name = shlaxfile.split('/')[-1].split('.')[0] - import importlib mod = importlib.import_module('shlax.repo.' + name) - for k, v in mod.__dict__.items(): - if callable(v): - break - self[name] = cli2.Callable(name, v, doc='lol') + self[name] = cli2.Callable(name, mod) return super().__call__(*args, **kwargs) diff --git a/shlax/repo/traefik.py b/shlax/repo/traefik.py index fc400bb..ee6b280 100755 --- a/shlax/repo/traefik.py +++ b/shlax/repo/traefik.py @@ -1,4 +1,8 @@ #!/usr/bin/env shlax +""" +Manage a traefik container maintained by Shlax community. +""" + from shlax import * main = Container( diff --git a/shlax/shlaxfile.py b/shlax/shlaxfile.py index c1039a5..0bb95fb 100644 --- a/shlax/shlaxfile.py +++ b/shlax/shlaxfile.py @@ -20,6 +20,7 @@ class Shlaxfile: self.actions[name] = value elif callable(value) and getattr(value, '__name__', '').startswith('test_'): self.tests[value.__name__] = value + self.paths.append(path) @property diff --git a/shlax/strategies/pod.py b/shlax/strategies/pod.py index 97da07c..fc22ca7 100644 --- a/shlax/strategies/pod.py +++ b/shlax/strategies/pod.py @@ -3,6 +3,17 @@ from .script import Script class Container(Script): + """ + Wolcome to crazy container control cli + + Such wow + """ + doc = dict( + build='Execute the Build script', + test='Execute the Test script (if any)', + push='Push the container (if Build script defines commit kwarg)', + ) + async def call(self, *args, **kwargs): if not args or 'build' in args: await self.kwargs['build'](**kwargs)