view mercurial/fancyopts.py @ 192:5d8553352d2e

Changes to network protocol -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Changes to network protocol Stream changes at the delta level rather than at whole delta groups this breaks the protocol - we now send a zero byte delta to indicate the end of a group rather than sending the entire group length up front Fix filename length asymmetry while we're breaking things Fix hidden O(n^2) bug in calculating changegroup list.append(e) is O(n), list + [element] is not Decompress chunks on read in revlog.group() Improve status messages report bytes transferred report nothing to do Deal with /dev/null path brokenness Remove untriggered patch assertion manifest hash: 3eedcfe878561f9eb4adedb04f6be618fb8ae8d8 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCmzlqywK+sNU5EO8RAn0KAJ4z4toWSSGjLoZO6FKWLx/3QbZufACglQgd S48bumc++DnuY1iPSNWKGAI= =lCjx -----END PGP SIGNATURE-----
author mpm@selenic.com
date Mon, 30 May 2005 08:03:54 -0800
parents 2e87f04880ab
children 63af1db35611
line wrap: on
line source

import sys, os, getopt

def fancyopts(args, options, state, syntax='', minlen = 0):
    long=[]
    short=''
    map={}
    dt={}

    def help(state, opt, arg, options=options, syntax=syntax):
        print "Usage: ", syntax

        for s, l, d, c in options:
            opt=' '
            if s: opt = opt + '-' + s + ' '
            if l: opt = opt + '--' + l + ' '
            if d: opt = opt + '(' + str(d) + ')'
            print opt
            if c: print '   %s' % c
        sys.exit(0)

    if len(args) < minlen:
        help(state, None, args)

    options=[('h', 'help', help, 'Show usage info')] + options
    
    for s, l, d, c in options:
        map['-'+s] = map['--'+l]=l
        state[l] = d
        dt[l] = type(d)
        if not d is None and not type(d) is type(help): s, l=s+':', l+'='      
        if s: short = short + s
        if l: long.append(l)

    if os.environ.has_key("HG_OPTS"):
        args = os.environ["HG_OPTS"].split() + args

    try:
        opts, args = getopt.getopt(args, short, long)
    except getopt.GetoptError:
        help(state, None, args)
        sys.exit(-1)

    for opt, arg in opts:
        if dt[map[opt]] is type(help): state[map[opt]](state,map[opt],arg)
        elif dt[map[opt]] is type(1): state[map[opt]] = int(arg)
        elif dt[map[opt]] is type(''): state[map[opt]] = arg
        elif dt[map[opt]] is type([]): state[map[opt]].append(arg)
        elif dt[map[opt]] is type(None): state[map[opt]] = 1
        
    return args