mercurial/fancyopts.py
author Brendan Cully <brendan@kublai.com>
Thu, 22 Mar 2007 10:44:59 -0700
changeset 4258 47ba52121433
parent 3749 f9567a7fa3b3
child 5145 88803a69b24a
permissions -rw-r--r--
Add import --exact. When this option is set, import will apply the patch (which must be generated by export) to the parents specified in the patch, and check that the node produced by the patch matches the node ID in the patch.

import getopt

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

    for s, l, d, c in options:
        pl = l.replace('-', '_')
        map['-'+s] = map['--'+l] = pl
        state[pl] = d
        dt[pl] = type(d)
        if (d is not None and d is not True and d is not False and
            not callable(d)):
            if s: s += ':'
            if l: l += '='
        if s: short = short + s
        if l: long.append(l)

    opts, args = getopt.getopt(args, short, long)

    for opt, arg in opts:
        if dt[map[opt]] is type(fancyopts): 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]] = True
        elif dt[map[opt]] is type(False): state[map[opt]] = True

    return args