##// END OF EJS Templates
fancyopts: Parse options that occur after arguments....
Augie Fackler -
r7772:88887054 default
parent child Browse files
Show More
@@ -1993,13 +1993,10 def guard(ui, repo, *args, **opts):
1993
1993
1994 With no arguments, print the currently active guards.
1994 With no arguments, print the currently active guards.
1995 With arguments, set guards for the named patch.
1995 With arguments, set guards for the named patch.
1996
1996 NOTE: Specifying negative guards now requires '--'.
1997 To set a negative guard "-foo" on topmost patch ("--" is needed so
1998 hg will not interpret "-foo" as an option):
1999 hg qguard -- -foo
2000
1997
2001 To set guards on another patch:
1998 To set guards on another patch:
2002 hg qguard other.patch +2.6.17 -stable
1999 hg qguard -- other.patch +2.6.17 -stable
2003 '''
2000 '''
2004 def status(idx):
2001 def status(idx):
2005 guards = q.series_guards[idx] or ['unguarded']
2002 guards = q.series_guards[idx] or ['unguarded']
@@ -2499,7 +2496,7 cmdtable = {
2499 (guard,
2496 (guard,
2500 [('l', 'list', None, _('list all patches and guards')),
2497 [('l', 'list', None, _('list all patches and guards')),
2501 ('n', 'none', None, _('drop all guards'))],
2498 ('n', 'none', None, _('drop all guards'))],
2502 _('hg qguard [-l] [-n] [PATCH] [+GUARD]... [-GUARD]...')),
2499 _('hg qguard [-l] [-n] -- [PATCH] [+GUARD]... [-GUARD]...')),
2503 'qheader': (header, [], _('hg qheader [PATCH]')),
2500 'qheader': (header, [], _('hg qheader [PATCH]')),
2504 "^qimport":
2501 "^qimport":
2505 (qimport,
2502 (qimport,
@@ -184,7 +184,7 def _parse(ui, args):
184 c.append((o[0], o[1], options[o[1]], o[3]))
184 c.append((o[0], o[1], options[o[1]], o[3]))
185
185
186 try:
186 try:
187 args = fancyopts.fancyopts(args, c, cmdoptions)
187 args = fancyopts.fancyopts(args, c, cmdoptions, True)
188 except fancyopts.getopt.GetoptError, inst:
188 except fancyopts.getopt.GetoptError, inst:
189 raise error.ParseError(cmd, inst)
189 raise error.ParseError(cmd, inst)
190
190
@@ -1,6 +1,32
1 import getopt
1 import getopt
2
2
3 def fancyopts(args, options, state):
3 def gnugetopt(args, options, longoptions):
4 """Parse options mostly like getopt.gnu_getopt.
5
6 This is different from getopt.gnu_getopt in that an argument of - will
7 become an argument of - instead of vanishing completely.
8 """
9 extraargs = []
10 if '--' in args:
11 stopindex = args.index('--')
12 extraargs = args[stopindex+1:]
13 args = args[:stopindex]
14 opts, parseargs = getopt.getopt(args, options, longoptions)
15 args = []
16 while parseargs:
17 arg = parseargs.pop(0)
18 if arg and arg[0] == '-' and len(arg) > 1:
19 parseargs.insert(0, arg)
20 topts, newparseargs = getopt.getopt(parseargs, options, longoptions)
21 opts = opts + topts
22 parseargs = newparseargs
23 else:
24 args.append(arg)
25 args.extend(extraargs)
26 return opts, args
27
28
29 def fancyopts(args, options, state, gnu=False):
4 """
30 """
5 read args, parse options, and store options in state
31 read args, parse options, and store options in state
6
32
@@ -52,7 +78,11 def fancyopts(args, options, state):
52 namelist.append(oname)
78 namelist.append(oname)
53
79
54 # parse arguments
80 # parse arguments
55 opts, args = getopt.getopt(args, shortlist, namelist)
81 if gnu:
82 parse = gnugetopt
83 else:
84 parse = getopt.getopt
85 opts, args = parse(args, shortlist, namelist)
56
86
57 # transfer result to state
87 # transfer result to state
58 for opt, val in opts:
88 for opt, val in opts:
@@ -53,7 +53,7 hg qselect a
53 echo % should push a.patch
53 echo % should push a.patch
54 hg qpush
54 hg qpush
55
55
56 hg qguard c.patch -a
56 hg qguard -- c.patch -a
57 echo % should print -a
57 echo % should print -a
58 hg qguard c.patch
58 hg qguard c.patch
59
59
@@ -95,7 +95,7 hg qpush
95 hg qpush
95 hg qpush
96 hg qpop -a
96 hg qpop -a
97
97
98 hg qguard a.patch +1 +2 -3
98 hg qguard -- a.patch +1 +2 -3
99 hg qselect 1 2 3
99 hg qselect 1 2 3
100 echo % list patches and guards
100 echo % list patches and guards
101 hg qguard -l
101 hg qguard -l
General Comments 0
You need to be logged in to leave comments. Login now