From 0e89097066d03dcf49c5d9094081161d8973b07f Mon Sep 17 00:00:00 2001 From: Martin Blazik Date: Fri, 2 Oct 2020 13:26:50 +0200 Subject: [PATCH] gws - Help script for gradle application --- bin/gws | 128 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 108 insertions(+), 20 deletions(-) diff --git a/bin/gws b/bin/gws index 7b1d0c3..57b0a39 100755 --- a/bin/gws +++ b/bin/gws @@ -1,26 +1,114 @@ #!/usr/bin/env python3 """ -gws = gw script - -alias cbx='gw clean build -x test' -alias cbt='gw clean build compileTestKotlin' - -compileTestKotlin -compositeTest -some script to compile - -# use cases -gws build test -gws test -gws composite -gws clean build -x test :test :tools - +TODO +could load shortcuts from envinroment """ -from sys import argv +import os +from sys import argv, exit + +shortcuts = { + 'buildTest': ['compileTestKotlin'], + 'btest': ['compileTestKotlin'], + 'composite': ['compositeTest'], + 'cb': ['clean', 'build'], + 'cbx': ['clean', 'build', '-x', 'test'], + 'cbt': ['clean', 'build', 'compileTestKotlin'], + '-nc': ['--no-build-cache'], + '-rr': ['--rerun-tasks'] +} + +# must keep next argument +options = 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 cbt + gws cbx :microservices:afm-exec-api + +Options + --dry doesn't start gw app +""" + + +def help(): + print(help_text) + show_shortcuts() + exit(0) + + + +def show_shortcuts(): + print('Shortcuts') + for key, value in shortcuts.items(): + print(' {} ... {}'.format(key, ' '.join(value))) + + + +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: + arg = next(iterator) + if arg in options: + yield [arg, next(iterator)] + else: + yield [arg] + except StopIteration: + break + + +def mix_task_modules(modules, tasks): + return (module + ':' + task for module in modules for task in tasks) + + +def remake(args, modules): + tasks = [] + options = [] + for item in split_options(args): + if item[0].startswith('-'): + options.extend(item) + else: + tasks.extend(item) + if modules and tasks: + return list(mix_task_modules(modules, tasks)) + options + else: + return tasks + modules + options + + +def prepare_args(args): + modules = list(filter(lambda value: value.startswith(':'), 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) + return list(args) + + +def prepare_command(args): + args = prepare_args(args) + return 'gw ' + ' '.join(args) + + +def main(args): + if (not args): + help() + cmd = prepare_command(args) + print('## ' + cmd) + if '--dry' not in args: + os.system(cmd) + + +if __name__ == '__main__': + main(argv[1:]) -modules = list(filter(lambda value: value.startswith(':'), argv[1:])) -args = [arg for arg in argv[1:] if arg not in modules] -print(args) -print(modules)