#!/usr/bin/env python

import os, sys, libkludge

reload(sys)  # Reload does the trick!
sys.setdefaultencoding('UTF8')

def global_usage():
  print """KLUDGE: KL wrapping tool

Global usage:
"""
  for command in libkludge.commands:
    print """%s %s %s
  %s""" % (
      'kludge',
      command.name,
      command.usage,
      command.description,
      )
  print """
Run %s <command> --help for more details of each command""" % sys.argv[0]
  sys.exit(1)

if len(sys.argv) < 2:
  global_usage()

for command in libkludge.commands:
  if sys.argv[1] == command.name:
    sys.exit(command.main(sys.argv[0], sys.argv[2:]))

print "Unrecognized command: %s" % sys.argv[1]
global_usage()
