import sys

program = {}
handlers = {}

def main(name, desc):
  program['name'] = name
  program['desc'] = desc
  
  if len(sys.argv) < 2:
    command, arguments = '', []
  else:
    command, arguments = sys.argv[1], sys.argv[2:]
  
  if command in handlers:
    handler = handlers[command]
  else:
    handler = help
  
  try:
    handler(*arguments)
  except Exception as e:
    print e.args

def cmd(handler):
  handlers[handler.__name__] = handler
  return handler

def default(handler):
  handlers[''] = handler
  return handler

def help():
  subcmds = []
  for name, handler in handlers.items():
    syntax = (program['name'] + ' ' + name).strip()
    usage = '  %s: %s' % (syntax, handler.__doc__)
    subcmds.append(usage)
  subcmds = '\n'.join(subcmds)
  
  doc = """%s

Usage:
%s""" % (program['desc'], subcmds)
  
  print doc

@@ -144,29 +144,24 @@
 command, arg
-ument
 s = '', %5B%5D%0A 
@@ -183,21 +183,16 @@
 and, arg
-ument
 s = sys.
@@ -212,24 +212,177 @@
 argv%5B2:%5D%0A  %0A
+  options = %7B%7D%0A  for i, arg in enumerate(args):%0A    if arg.startswith('--'):%0A      opt = arg.lstrip('--')%0A      options%5Bopt%5D = True%0A      del args%5Bi%5D%0A  %0A
   if command
@@ -484,13 +484,19 @@
 *arg
-ument
+s, **option
 s)%0A 

support --options in cmdapp.py