mercurial/fancyopts.py
author Bryan O'Sullivan <bos@serpentine.com>
Thu, 22 Sep 2005 21:15:57 -0700
changeset 1317 008d3666bf41
parent 1056 34be48b4ca85
child 1541 bf4e7ef08741
permissions -rw-r--r--
Print commit time/date from perspective of committer. Previously, it was printed in the time zone of the reader, but with the committer's time zone offset. It is now consistent.

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 not d is None 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]] = 1

    return args