Show More
@@ -12,6 +12,17 b' import getopt' | |||||
12 | from .i18n import _ |
|
12 | from .i18n import _ | |
13 | from . import error |
|
13 | from . import error | |
14 |
|
14 | |||
|
15 | # Set of flags to not apply boolean negation logic on | |||
|
16 | nevernegate = set([ | |||
|
17 | # avoid --no-noninteractive | |||
|
18 | 'noninteractive', | |||
|
19 | # These two flags are special because they cause hg to do one | |||
|
20 | # thing and then exit, and so aren't suitable for use in things | |||
|
21 | # like aliases anyway. | |||
|
22 | 'help', | |||
|
23 | 'version', | |||
|
24 | ]) | |||
|
25 | ||||
15 | def gnugetopt(args, options, longoptions): |
|
26 | def gnugetopt(args, options, longoptions): | |
16 | """Parse options mostly like getopt.gnu_getopt. |
|
27 | """Parse options mostly like getopt.gnu_getopt. | |
17 |
|
28 | |||
@@ -64,6 +75,8 b' def fancyopts(args, options, state, gnu=' | |||||
64 | shortlist = '' |
|
75 | shortlist = '' | |
65 | argmap = {} |
|
76 | argmap = {} | |
66 | defmap = {} |
|
77 | defmap = {} | |
|
78 | negations = {} | |||
|
79 | alllong = set(o[1] for o in options) | |||
67 |
|
80 | |||
68 | for option in options: |
|
81 | for option in options: | |
69 | if len(option) == 5: |
|
82 | if len(option) == 5: | |
@@ -91,6 +104,18 b' def fancyopts(args, options, state, gnu=' | |||||
91 | short += ':' |
|
104 | short += ':' | |
92 | if oname: |
|
105 | if oname: | |
93 | oname += '=' |
|
106 | oname += '=' | |
|
107 | elif oname not in nevernegate: | |||
|
108 | if oname.startswith('no-'): | |||
|
109 | insert = oname[3:] | |||
|
110 | else: | |||
|
111 | insert = 'no-' + oname | |||
|
112 | # backout (as a practical example) has both --commit and | |||
|
113 | # --no-commit options, so we don't want to allow the | |||
|
114 | # negations of those flags. | |||
|
115 | if insert not in alllong: | |||
|
116 | assert ('--' + oname) not in negations | |||
|
117 | negations['--' + insert] = '--' + oname | |||
|
118 | namelist.append(insert) | |||
94 | if short: |
|
119 | if short: | |
95 | shortlist += short |
|
120 | shortlist += short | |
96 | if name: |
|
121 | if name: | |
@@ -105,6 +130,11 b' def fancyopts(args, options, state, gnu=' | |||||
105 |
|
130 | |||
106 | # transfer result to state |
|
131 | # transfer result to state | |
107 | for opt, val in opts: |
|
132 | for opt, val in opts: | |
|
133 | boolval = True | |||
|
134 | negation = negations.get(opt, False) | |||
|
135 | if negation: | |||
|
136 | opt = negation | |||
|
137 | boolval = False | |||
108 | name = argmap[opt] |
|
138 | name = argmap[opt] | |
109 | obj = defmap[name] |
|
139 | obj = defmap[name] | |
110 | t = type(obj) |
|
140 | t = type(obj) | |
@@ -121,7 +151,7 b' def fancyopts(args, options, state, gnu=' | |||||
121 | elif t is type([]): |
|
151 | elif t is type([]): | |
122 | state[name].append(val) |
|
152 | state[name].append(val) | |
123 | elif t is type(None) or t is type(False): |
|
153 | elif t is type(None) or t is type(False): | |
124 |
state[name] = |
|
154 | state[name] = boolval | |
125 |
|
155 | |||
126 | # return unparsed args |
|
156 | # return unparsed args | |
127 | return args |
|
157 | return args |
@@ -379,3 +379,14 b' Test experimental revset support' | |||||
379 |
|
379 | |||
380 | $ hg log -r '_destupdate()' |
|
380 | $ hg log -r '_destupdate()' | |
381 | 2:bd10386d478c 2 (no-eol) |
|
381 | 2:bd10386d478c 2 (no-eol) | |
|
382 | ||||
|
383 | Test that boolean flags allow --no-flag specification to override [defaults] | |||
|
384 | $ cat >> $HGRCPATH <<EOF | |||
|
385 | > [defaults] | |||
|
386 | > update = --check | |||
|
387 | > EOF | |||
|
388 | $ hg co 2 | |||
|
389 | abort: uncommitted changes | |||
|
390 | [255] | |||
|
391 | $ hg co --no-check 2 | |||
|
392 | 0 files updated, 0 files merged, 0 files removed, 0 files unresolved |
General Comments 0
You need to be logged in to leave comments.
Login now