comparison mx/mx_graal.py @ 13507:d3ec6003856d

mx: experimental autocompletion generation for zsh (GRAAL-297)
author Bernhard Urban <bernhard.urban@jku.at>
date Fri, 03 Jan 2014 16:36:15 +0200
parents 441b54753cda
children 8a5b39d0bfb5
comparison
equal deleted inserted replaced
13506:2a4569fa9aa4 13507:d3ec6003856d
1381 '--jd', '@-tag', '--jd', '@vmoption:X', 1381 '--jd', '@-tag', '--jd', '@vmoption:X',
1382 '--overview', join(_graal_home, 'graal', 'overview.html'), 1382 '--overview', join(_graal_home, 'graal', 'overview.html'),
1383 '--title', 'Graal OpenJDK Project Documentation', 1383 '--title', 'Graal OpenJDK Project Documentation',
1384 '--dot-output-base', 'projects'] + args) 1384 '--dot-output-base', 'projects'] + args)
1385 1385
1386 def generateZshCompletion(args):
1387 """generate zsh completion for mx"""
1388 try:
1389 from genzshcomp import CompletionGenerator
1390 except ImportError:
1391 mx.abort("install genzshcomp (pip install genzshcomp)")
1392
1393 # need to fake module for the custom mx arg parser, otherwise a check in genzshcomp fails
1394 originalModule = mx._argParser.__module__
1395 mx._argParser.__module__ = "argparse"
1396 generator = CompletionGenerator("mx", mx._argParser)
1397 mx._argParser.__module__ = originalModule
1398
1399 # strip last line and define local variable "ret"
1400 complt = "\n".join(generator.get().split('\n')[0:-1]).replace('context state line', 'context state line ret=1')
1401
1402 # add array of possible subcommands (as they are not part of the argument parser)
1403 complt += '\n ": :->command" \\\n'
1404 complt += ' "*::args:_files" && ret=0\n'
1405 complt += '\n'
1406 complt += 'case $state in\n'
1407 complt += ' (command)\n'
1408 complt += ' local -a main_commands\n'
1409 complt += ' main_commands=(\n'
1410 for cmd in sorted(mx._commands.iterkeys()):
1411 c, _ = mx._commands[cmd][:2]
1412 doc = c.__doc__
1413 complt += ' "{0}'.format(cmd)
1414 if doc:
1415 complt += ':{0}'.format(doc.split('\n', 1)[0].replace('\"', '').replace("\'", ""))
1416 complt += '"\n'
1417 complt += ' )\n'
1418 complt += ' _describe -t main_commands command main_commands && ret=0\n'
1419 complt += ' ;;\n'
1420 complt += 'esac\n'
1421 complt += '\n'
1422 complt += 'return $ret'
1423 print complt
1424
1425
1386 def mx_init(suite): 1426 def mx_init(suite):
1387 commands = { 1427 commands = {
1388 'build': [build, ''], 1428 'build': [build, ''],
1389 'buildvars': [buildvars, ''], 1429 'buildvars': [buildvars, ''],
1390 'buildvms': [buildvms, '[-options]'], 1430 'buildvms': [buildvms, '[-options]'],
1391 'clean': [clean, ''], 1431 'clean': [clean, ''],
1432 'generateZshCompletion' : [generateZshCompletion, ''],
1392 'hsdis': [hsdis, '[att]'], 1433 'hsdis': [hsdis, '[att]'],
1393 'hcfdis': [hcfdis, ''], 1434 'hcfdis': [hcfdis, ''],
1394 'igv' : [igv, ''], 1435 'igv' : [igv, ''],
1395 'jdkhome': [print_jdkhome, ''], 1436 'jdkhome': [print_jdkhome, ''],
1396 'dacapo': [dacapo, '[VM options] benchmarks...|"all" [DaCapo options]'], 1437 'dacapo': [dacapo, '[VM options] benchmarks...|"all" [DaCapo options]'],