from ctl import HavenCtl

def execute_from_command_line():
    begin_havenctl_repl()

def begin_havenctl_repl():
    HavenCtl().cmdloop()

@@ -1,12 +1,38 @@
+import sys%0Aimport getopt%0A%0A
 from ctl imp
@@ -53,105 +53,1266 @@
 def 
-execute_from_command_line():%0A    begin_havenctl_repl()%0A%0Adef begin_havenctl_repl():%0A    HavenCtl()
+print_version():%0A    import pkg_resources  # part of setuptools%0A    version = pkg_resources.require(%22havenctl%22)%5B0%5D.version%0A    print(version)%0A%0Adef print_usage():%0A    print %22%22%22%0AUsage: havenctl %5B-a %3Cremote_address%3E %7C --address=%3Cremote_address%3E%5D%0A                %5B-p %3Cremote_port%3E %7C --port=%3Cremote_port%3E%5D %5B-hv%5D cmd%0A    %22%22%22%0A%0Adef execute_from_command_line():%0A    try:%0A        opts, args = getopt.getopt(sys.argv%5B1:%5D, %22a:p:hv%22, %5C%0A                %5B%22address=%22, %22port=%22, %22version%22, %22help%22%5D)%0A%0A    except getopt.GetoptError, err:%0A        print str(err)%0A        usage()%0A        sys.exit(2)%0A%0A    for o, a in opts:%0A        if o in (%22-h%22, %22--help%22):%0A            print_usage()%0A            sys.exit()%0A        elif o in (%22-v%22, %22--version%22):%0A            print_version()%0A            sys.exit()%0A        elif o in (%22-a%22, %22--address%22):%0A            address = a%0A        elif o in (%22-p%22, %22--port%22):%0A            port = a%0A        else:%0A            usage()%0A            assert False, %22unhandled option%22%0A            sys.exit(2)%0A%0A    handle_user_args(address, port, %22 %22.join(args))%0A%0Adef handle_user_args(address, port, cmd):%0A    repl = HavenCtl()%0A%0A    if(address):%0A        repl.onecmd(%22connect %22 + str(address) + %22 %22 + str(port))%0A%0A    if(cmd):%0A        repl.onecmd(cmd)%0A    else:%0A        repl
 .cmd

Handle command line args.