gws - Help script for gradle application
This commit is contained in:
128
bin/gws
128
bin/gws
@@ -1,26 +1,114 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
"""
|
"""
|
||||||
gws = gw script
|
TODO
|
||||||
|
could load shortcuts from envinroment
|
||||||
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
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
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)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user