Files
linux-workspace/bin/gws
2020-10-02 15:28:54 +02:00

110 lines
2.3 KiB
Python
Executable File

#!/usr/bin/env python3
"""
TODO
could load shortcuts from environment
"""
import os
from sys import argv, exit
shortcuts = {
'bt': ['compileTestKotlin'],
'ct': ['componentTest'],
'cb': ['clean', 'build'],
'cbx': ['clean', 'build', '-x', 'test'],
'cbt': ['clean', 'build', 'compileTestKotlin'],
'-nc': ['--no-build-cache'],
'-rr': ['--rerun-tasks']
}
optionsWithArgument = set(['-x', '-b', '-c', '-g', '-p', '-D', '-I', '-P'])
help_text = """\
Support functionality for gw application
Use cases
gws clean build -x test :test :tools
gws cb ct
gws cbt
gws cbx :microservices:afm-exec-api
Options
--dry doesn't start gw app
"""
def show_help():
print(help_text)
show_shortcuts()
print()
exit(1)
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 optionsWithArgument:
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:
show_help()
cmd = prepare_command(args)
print('## ' + cmd)
if '--dry' not in args:
os.system(cmd)
if __name__ == '__main__':
main(argv[1:])