         print(version)
         exit()
 
+class Dict extends Object
+    constructor: (pairs) ->
+        (@[key] = value for [key, value] in pairs)
+    toString: () ->
+        '{' + (k + ': ' + @[k] for k of @).join(',\n  ') + '}'
+
 docopt = (doc, argv=process.argv[1..], name=null, help=true, version=null) ->
     DocoptExit.usage = docopt.usage = usage = printable_usage(doc, name)
     pot_options = parse_doc_options(doc)
-    [options, args] = parse_args(argv, options=pot_options)
+    [options, args] = parse_args(argv, pot_options)
 
     extras(help, version, options, doc)
-    formal_pattern = parse_pattern(formal_usage(usage), options=pot_options)
-#    pot_arguments = [a for a in formal_pattern.flat
-#                     if type(a) in [Argument, Command]]
+    formal_pattern = parse_pattern(formal_usage(usage), pot_options)
+#    pot_arguments = (a for a in formal_pattern.flat
+#                     if a.constructor in [Argument, Command])
 #    [matched, left, arguments] = formal_pattern.fix().match(argv)
 #    if matched and left == []:  # better message if left?
 #        args = Dict((a.name, a.value) for a in

print = console.log

class UsageMessageError extends Error
    constructor: (message) ->

    (Option.parse('-' + s) for s in doc.split(/^ *-|\n *-/)[1..])

printable_usage = (doc, name) ->
    [usage, patterns] = doc.split(/(?:^|\n)([\s^\n]*usage:\s*)/i)[1..2]
    usage = usage.replace(/^\s+/, '')
    if not /\s$/.test(usage) then usage += ' '
    indent = '\n' + /(^)?[^\n]*$/.exec(usage)[0].replace(/./g, (c) ->
       return (if c is '\t' then '\t' else ' '))
    oldname = /^[^\s]+/.exec(patterns)[0]
    if name is null then name = oldname
    uses = patterns.split(/\n\s*\n/)[0]
    uses = uses.split(new RegExp('(?:^|\\n)\\s*' + oldname))
    uses = (name + u.replace /\s+$/, '' for u in uses[1..])
    return usage + uses.join(indent)

formal_usage = (printable_usage) ->
    pu = printable_usage.split()[1..]  # split and drop "usage:"
