#!/usr/bin/env python
"""Expose command line interfaces of modules in package."""
from __future__ import print_function
import os
import sys

COMMANDS = (
		('runexp', 'Run experiment: grammar extraction, parsing & evaluation.'),
		('fragments', 'Extract recurring fragments from treebanks.'),
		('eval', 'Evaluate discontinuous parse trees; similar to EVALB.'),
		('treetransforms', 'Apply tree transformations '
			'and convert between formats.'),
		('treedraw', 'Visualize (discontinuous) trees.'),
		('treesearch', 'Query treebanks.'),
		('grammar', 'Read off grammars from treebanks.'),
		('parser', 'Simple command line parser.'),
		('demos', 'Show some demonstrations of formalisms encoded in LCFRS.'),
		('gen', 'Generate sentences from a PLCFRS.'),
)

thiscmd = os.path.basename(sys.argv[0])
if len(sys.argv) <= 1 or sys.argv[1] not in dict(COMMANDS):
	print('Usage: %s <command> [arguments]\n' % thiscmd, file=sys.stderr)
	print('Command is one of:', file=sys.stderr)
	for a, b in COMMANDS:
		print('   %s  %s' % (a.ljust(15), b))
	print('for additional instructions issue: %s <command> --help' % thiscmd,
		file=sys.stderr)
elif len(sys.argv) == 3 and sys.argv[2] in ('-h', '--help'):
	os.execlp('man', 'man', 'discodop-%s' % sys.argv[1])
else:
	cmd = sys.argv[1]
	getattr(__import__('discodop.cli', fromlist=[cmd]), cmd)()
