From 1fc9955ff5d8cfbd8a278d7a174b843cf9b48a99 Mon Sep 17 00:00:00 2001 From: Martin Blazik Date: Fri, 2 Oct 2020 15:28:54 +0200 Subject: [PATCH] Refactorization of gws --- bin/gws | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/bin/gws b/bin/gws index 57b0a39..76569a5 100755 --- a/bin/gws +++ b/bin/gws @@ -2,16 +2,15 @@ """ TODO -could load shortcuts from envinroment +could load shortcuts from environment """ import os from sys import argv, exit shortcuts = { - 'buildTest': ['compileTestKotlin'], - 'btest': ['compileTestKotlin'], - 'composite': ['compositeTest'], + 'bt': ['compileTestKotlin'], + 'ct': ['componentTest'], 'cb': ['clean', 'build'], 'cbx': ['clean', 'build', '-x', 'test'], 'cbt': ['clean', 'build', 'compileTestKotlin'], @@ -19,16 +18,14 @@ shortcuts = { '-rr': ['--rerun-tasks'] } -# must keep next argument -options = set(['-x', '-b', '-c', '-g', '-p', '-D', '-I', '-P']) +optionsWithArgument = set(['-x', '-b', '-c', '-g', '-p', '-D', '-I', '-P']) help_text = """\ Support functionality for gw application -gws means gw script Use cases gws clean build -x test :test :tools - gws cb + gws cb ct gws cbt gws cbx :microservices:afm-exec-api @@ -37,11 +34,11 @@ Options """ -def help(): +def show_help(): print(help_text) show_shortcuts() - exit(0) - + print() + exit(1) def show_shortcuts(): @@ -50,29 +47,28 @@ def show_shortcuts(): print(' {} ... {}'.format(key, ' '.join(value))) - -def flat_map(f, xs): +def flat_map(f, xs): return (y for ys in xs for y in f(ys)) def split_options(args): iterator = iter(args) - while True: - try: + while True: + try: arg = next(iterator) - if arg in options: + if arg in optionsWithArgument: yield [arg, next(iterator)] else: yield [arg] - except StopIteration: + except StopIteration: break -def mix_task_modules(modules, tasks): +def mix_task_modules(modules, tasks): return (module + ':' + task for module in modules for task in tasks) -def remake(args, modules): +def remake(args, modules): tasks = [] options = [] for item in split_options(args): @@ -91,7 +87,7 @@ def prepare_args(args): args = (arg for arg in argv[1:] if arg not in modules) args = flat_map(lambda arg: shortcuts.get(arg, [arg]), args) args = list(args) - args = remake(args, modules) + args = remake(args, modules) return list(args) @@ -100,9 +96,9 @@ def prepare_command(args): return 'gw ' + ' '.join(args) -def main(args): - if (not args): - help() +def main(args): + if not args: + show_help() cmd = prepare_command(args) print('## ' + cmd) if '--dry' not in args: @@ -111,4 +107,3 @@ def main(args): if __name__ == '__main__': main(argv[1:]) -