Refactorization of gws

This commit is contained in:
Martin Blazik
2020-10-02 15:28:54 +02:00
parent 8cb6cc467b
commit 1fc9955ff5

43
bin/gws
View File

@@ -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:])