view mercurial/fancyopts.py @ 706:5107a7b6b14a

Make "hg parents REV" work (again?) -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Make "hg parents REV" work (again?) manifest hash: d14db0d23b539ad0b754a51a83926d14f1be9a6e -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFC12adW7P1GVgWeRoRAtknAJ9TeUybLWYWY+Bi2b5grmAspgfemwCeP9cd 6mYSTWIsovCqW59KIrEvVVo= =u5nR -----END PGP SIGNATURE-----
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 15 Jul 2005 08:32:45 +0100
parents 31a9aa890016
children 0aaeee519c66 4f81068ed8cd
line wrap: on
line source

import getopt

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

    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 callable(d): s, l=s+':', 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