Mercurial > hg
annotate mercurial/fancyopts.py @ 30320:bff5ccbe5ead stable
vfs: ignore EPERM at os.utime, which avoids ambiguity at renaming (issue5418)
According to POSIX specification, just having group write access to a
file causes EPERM at invocation of os.utime() with an explicit time
information (e.g. working on the repository shared by group access
permission).
To ignore EPERM at renaming in such case, this patch makes
vfs.rename() use filestat.avoidambig() introduced by previous patch.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Sun, 13 Nov 2016 06:11:56 +0900 |
parents | e1f0ec0b7d2d |
children | c6ce11f2ee50 |
rev | line source |
---|---|
8230
ec98f35e3e16
fancyopts: add copyright and license header
Martin Geisler <mg@lazybytes.net>
parents:
7772
diff
changeset
|
1 # fancyopts.py - better command line parsing |
ec98f35e3e16
fancyopts: add copyright and license header
Martin Geisler <mg@lazybytes.net>
parents:
7772
diff
changeset
|
2 # |
ec98f35e3e16
fancyopts: add copyright and license header
Martin Geisler <mg@lazybytes.net>
parents:
7772
diff
changeset
|
3 # Copyright 2005-2009 Matt Mackall <mpm@selenic.com> and others |
ec98f35e3e16
fancyopts: add copyright and license header
Martin Geisler <mg@lazybytes.net>
parents:
7772
diff
changeset
|
4 # |
ec98f35e3e16
fancyopts: add copyright and license header
Martin Geisler <mg@lazybytes.net>
parents:
7772
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
10263 | 6 # GNU General Public License version 2 or any later version. |
8230
ec98f35e3e16
fancyopts: add copyright and license header
Martin Geisler <mg@lazybytes.net>
parents:
7772
diff
changeset
|
7 |
25947
6002e2d95e54
fancyopts: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25563
diff
changeset
|
8 from __future__ import absolute_import |
6002e2d95e54
fancyopts: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25563
diff
changeset
|
9 |
20034
1e5b38a919dd
cleanup: move stdlib imports to their own import statement
Augie Fackler <raf@durin42.com>
parents:
17712
diff
changeset
|
10 import getopt |
25947
6002e2d95e54
fancyopts: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25563
diff
changeset
|
11 |
6002e2d95e54
fancyopts: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25563
diff
changeset
|
12 from .i18n import _ |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25947
diff
changeset
|
13 from . import error |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
14 |
29947
e1f0ec0b7d2d
flags: allow specifying --no-boolean-flag on the command line (BC)
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
15 # Set of flags to not apply boolean negation logic on |
e1f0ec0b7d2d
flags: allow specifying --no-boolean-flag on the command line (BC)
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
16 nevernegate = set([ |
e1f0ec0b7d2d
flags: allow specifying --no-boolean-flag on the command line (BC)
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
17 # avoid --no-noninteractive |
e1f0ec0b7d2d
flags: allow specifying --no-boolean-flag on the command line (BC)
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
18 'noninteractive', |
e1f0ec0b7d2d
flags: allow specifying --no-boolean-flag on the command line (BC)
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
19 # These two flags are special because they cause hg to do one |
e1f0ec0b7d2d
flags: allow specifying --no-boolean-flag on the command line (BC)
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
20 # thing and then exit, and so aren't suitable for use in things |
e1f0ec0b7d2d
flags: allow specifying --no-boolean-flag on the command line (BC)
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
21 # like aliases anyway. |
e1f0ec0b7d2d
flags: allow specifying --no-boolean-flag on the command line (BC)
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
22 'help', |
e1f0ec0b7d2d
flags: allow specifying --no-boolean-flag on the command line (BC)
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
23 'version', |
e1f0ec0b7d2d
flags: allow specifying --no-boolean-flag on the command line (BC)
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
24 ]) |
e1f0ec0b7d2d
flags: allow specifying --no-boolean-flag on the command line (BC)
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
25 |
7772
88887054d277
fancyopts: Parse options that occur after arguments.
Augie Fackler <durin42@gmail.com>
parents:
5878
diff
changeset
|
26 def gnugetopt(args, options, longoptions): |
88887054d277
fancyopts: Parse options that occur after arguments.
Augie Fackler <durin42@gmail.com>
parents:
5878
diff
changeset
|
27 """Parse options mostly like getopt.gnu_getopt. |
88887054d277
fancyopts: Parse options that occur after arguments.
Augie Fackler <durin42@gmail.com>
parents:
5878
diff
changeset
|
28 |
88887054d277
fancyopts: Parse options that occur after arguments.
Augie Fackler <durin42@gmail.com>
parents:
5878
diff
changeset
|
29 This is different from getopt.gnu_getopt in that an argument of - will |
88887054d277
fancyopts: Parse options that occur after arguments.
Augie Fackler <durin42@gmail.com>
parents:
5878
diff
changeset
|
30 become an argument of - instead of vanishing completely. |
88887054d277
fancyopts: Parse options that occur after arguments.
Augie Fackler <durin42@gmail.com>
parents:
5878
diff
changeset
|
31 """ |
88887054d277
fancyopts: Parse options that occur after arguments.
Augie Fackler <durin42@gmail.com>
parents:
5878
diff
changeset
|
32 extraargs = [] |
88887054d277
fancyopts: Parse options that occur after arguments.
Augie Fackler <durin42@gmail.com>
parents:
5878
diff
changeset
|
33 if '--' in args: |
88887054d277
fancyopts: Parse options that occur after arguments.
Augie Fackler <durin42@gmail.com>
parents:
5878
diff
changeset
|
34 stopindex = args.index('--') |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
35 extraargs = args[stopindex + 1:] |
7772
88887054d277
fancyopts: Parse options that occur after arguments.
Augie Fackler <durin42@gmail.com>
parents:
5878
diff
changeset
|
36 args = args[:stopindex] |
88887054d277
fancyopts: Parse options that occur after arguments.
Augie Fackler <durin42@gmail.com>
parents:
5878
diff
changeset
|
37 opts, parseargs = getopt.getopt(args, options, longoptions) |
88887054d277
fancyopts: Parse options that occur after arguments.
Augie Fackler <durin42@gmail.com>
parents:
5878
diff
changeset
|
38 args = [] |
88887054d277
fancyopts: Parse options that occur after arguments.
Augie Fackler <durin42@gmail.com>
parents:
5878
diff
changeset
|
39 while parseargs: |
88887054d277
fancyopts: Parse options that occur after arguments.
Augie Fackler <durin42@gmail.com>
parents:
5878
diff
changeset
|
40 arg = parseargs.pop(0) |
88887054d277
fancyopts: Parse options that occur after arguments.
Augie Fackler <durin42@gmail.com>
parents:
5878
diff
changeset
|
41 if arg and arg[0] == '-' and len(arg) > 1: |
88887054d277
fancyopts: Parse options that occur after arguments.
Augie Fackler <durin42@gmail.com>
parents:
5878
diff
changeset
|
42 parseargs.insert(0, arg) |
88887054d277
fancyopts: Parse options that occur after arguments.
Augie Fackler <durin42@gmail.com>
parents:
5878
diff
changeset
|
43 topts, newparseargs = getopt.getopt(parseargs, options, longoptions) |
88887054d277
fancyopts: Parse options that occur after arguments.
Augie Fackler <durin42@gmail.com>
parents:
5878
diff
changeset
|
44 opts = opts + topts |
88887054d277
fancyopts: Parse options that occur after arguments.
Augie Fackler <durin42@gmail.com>
parents:
5878
diff
changeset
|
45 parseargs = newparseargs |
88887054d277
fancyopts: Parse options that occur after arguments.
Augie Fackler <durin42@gmail.com>
parents:
5878
diff
changeset
|
46 else: |
88887054d277
fancyopts: Parse options that occur after arguments.
Augie Fackler <durin42@gmail.com>
parents:
5878
diff
changeset
|
47 args.append(arg) |
88887054d277
fancyopts: Parse options that occur after arguments.
Augie Fackler <durin42@gmail.com>
parents:
5878
diff
changeset
|
48 args.extend(extraargs) |
88887054d277
fancyopts: Parse options that occur after arguments.
Augie Fackler <durin42@gmail.com>
parents:
5878
diff
changeset
|
49 return opts, args |
88887054d277
fancyopts: Parse options that occur after arguments.
Augie Fackler <durin42@gmail.com>
parents:
5878
diff
changeset
|
50 |
88887054d277
fancyopts: Parse options that occur after arguments.
Augie Fackler <durin42@gmail.com>
parents:
5878
diff
changeset
|
51 |
88887054d277
fancyopts: Parse options that occur after arguments.
Augie Fackler <durin42@gmail.com>
parents:
5878
diff
changeset
|
52 def fancyopts(args, options, state, gnu=False): |
5638
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
53 """ |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
54 read args, parse options, and store options in state |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
55 |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
56 each option is a tuple of: |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
57 |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
58 short option or '' |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
59 long option |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
60 default value |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
61 description |
11321
40c06bbf58be
help: show value requirement and multiple occurrence of options
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
10282
diff
changeset
|
62 option value label(optional) |
5638
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
63 |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
64 option types include: |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
65 |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
66 boolean or none - option sets variable in state to true |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
67 string - parameter string is stored in state |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
68 list - parameter string is added to a list |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
69 integer - parameter strings is stored as int |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
70 function - call function with parameter |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
71 |
5638
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
72 non-option args are returned |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
73 """ |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
74 namelist = [] |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
75 shortlist = '' |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
76 argmap = {} |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
77 defmap = {} |
29947
e1f0ec0b7d2d
flags: allow specifying --no-boolean-flag on the command line (BC)
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
78 negations = {} |
e1f0ec0b7d2d
flags: allow specifying --no-boolean-flag on the command line (BC)
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
79 alllong = set(o[1] for o in options) |
5638
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
80 |
11321
40c06bbf58be
help: show value requirement and multiple occurrence of options
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
10282
diff
changeset
|
81 for option in options: |
40c06bbf58be
help: show value requirement and multiple occurrence of options
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
10282
diff
changeset
|
82 if len(option) == 5: |
40c06bbf58be
help: show value requirement and multiple occurrence of options
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
10282
diff
changeset
|
83 short, name, default, comment, dummy = option |
40c06bbf58be
help: show value requirement and multiple occurrence of options
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
10282
diff
changeset
|
84 else: |
40c06bbf58be
help: show value requirement and multiple occurrence of options
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
10282
diff
changeset
|
85 short, name, default, comment = option |
5638
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
86 # convert opts to getopt format |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
87 oname = name |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
88 name = name.replace('-', '_') |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
89 |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
90 argmap['-' + short] = argmap['--' + oname] = name |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
91 defmap[name] = default |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
92 |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
93 # copy defaults to state |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
94 if isinstance(default, list): |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
95 state[name] = default[:] |
21794
753af9ee7c81
fancyopts: restore use of callable() since it was readded in Python 3.2
Augie Fackler <raf@durin42.com>
parents:
20034
diff
changeset
|
96 elif callable(default): |
5638
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
97 state[name] = None |
5093
88803a69b24a
fancyopts: Copy list arguments in command table before modifying.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3749
diff
changeset
|
98 else: |
5638
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
99 state[name] = default |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
100 |
5638
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
101 # does it take a parameter? |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
102 if not (default is None or default is True or default is False): |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
103 if short: |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
104 short += ':' |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
105 if oname: |
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
106 oname += '=' |
29947
e1f0ec0b7d2d
flags: allow specifying --no-boolean-flag on the command line (BC)
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
107 elif oname not in nevernegate: |
e1f0ec0b7d2d
flags: allow specifying --no-boolean-flag on the command line (BC)
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
108 if oname.startswith('no-'): |
e1f0ec0b7d2d
flags: allow specifying --no-boolean-flag on the command line (BC)
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
109 insert = oname[3:] |
e1f0ec0b7d2d
flags: allow specifying --no-boolean-flag on the command line (BC)
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
110 else: |
e1f0ec0b7d2d
flags: allow specifying --no-boolean-flag on the command line (BC)
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
111 insert = 'no-' + oname |
e1f0ec0b7d2d
flags: allow specifying --no-boolean-flag on the command line (BC)
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
112 # backout (as a practical example) has both --commit and |
e1f0ec0b7d2d
flags: allow specifying --no-boolean-flag on the command line (BC)
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
113 # --no-commit options, so we don't want to allow the |
e1f0ec0b7d2d
flags: allow specifying --no-boolean-flag on the command line (BC)
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
114 # negations of those flags. |
e1f0ec0b7d2d
flags: allow specifying --no-boolean-flag on the command line (BC)
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
115 if insert not in alllong: |
e1f0ec0b7d2d
flags: allow specifying --no-boolean-flag on the command line (BC)
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
116 assert ('--' + oname) not in negations |
e1f0ec0b7d2d
flags: allow specifying --no-boolean-flag on the command line (BC)
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
117 negations['--' + insert] = '--' + oname |
e1f0ec0b7d2d
flags: allow specifying --no-boolean-flag on the command line (BC)
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
118 namelist.append(insert) |
5638
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
119 if short: |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
120 shortlist += short |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
121 if name: |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
122 namelist.append(oname) |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
123 |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
124 # parse arguments |
7772
88887054d277
fancyopts: Parse options that occur after arguments.
Augie Fackler <durin42@gmail.com>
parents:
5878
diff
changeset
|
125 if gnu: |
88887054d277
fancyopts: Parse options that occur after arguments.
Augie Fackler <durin42@gmail.com>
parents:
5878
diff
changeset
|
126 parse = gnugetopt |
88887054d277
fancyopts: Parse options that occur after arguments.
Augie Fackler <durin42@gmail.com>
parents:
5878
diff
changeset
|
127 else: |
88887054d277
fancyopts: Parse options that occur after arguments.
Augie Fackler <durin42@gmail.com>
parents:
5878
diff
changeset
|
128 parse = getopt.getopt |
88887054d277
fancyopts: Parse options that occur after arguments.
Augie Fackler <durin42@gmail.com>
parents:
5878
diff
changeset
|
129 opts, args = parse(args, shortlist, namelist) |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
130 |
5638
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
131 # transfer result to state |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
132 for opt, val in opts: |
29947
e1f0ec0b7d2d
flags: allow specifying --no-boolean-flag on the command line (BC)
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
133 boolval = True |
e1f0ec0b7d2d
flags: allow specifying --no-boolean-flag on the command line (BC)
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
134 negation = negations.get(opt, False) |
e1f0ec0b7d2d
flags: allow specifying --no-boolean-flag on the command line (BC)
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
135 if negation: |
e1f0ec0b7d2d
flags: allow specifying --no-boolean-flag on the command line (BC)
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
136 opt = negation |
e1f0ec0b7d2d
flags: allow specifying --no-boolean-flag on the command line (BC)
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
137 boolval = False |
5638
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
138 name = argmap[opt] |
25563
69e8384a436c
fancyopts: allow all callable as default parameter value
introom <i@introo.me>
parents:
21794
diff
changeset
|
139 obj = defmap[name] |
69e8384a436c
fancyopts: allow all callable as default parameter value
introom <i@introo.me>
parents:
21794
diff
changeset
|
140 t = type(obj) |
69e8384a436c
fancyopts: allow all callable as default parameter value
introom <i@introo.me>
parents:
21794
diff
changeset
|
141 if callable(obj): |
5638
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
142 state[name] = defmap[name](val) |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
143 elif t is type(1): |
17712
c4717f44c1f1
fancyopts: don't show a traceback on invalid integer values
Idan Kamara <idankk86@gmail.com>
parents:
14943
diff
changeset
|
144 try: |
c4717f44c1f1
fancyopts: don't show a traceback on invalid integer values
Idan Kamara <idankk86@gmail.com>
parents:
14943
diff
changeset
|
145 state[name] = int(val) |
c4717f44c1f1
fancyopts: don't show a traceback on invalid integer values
Idan Kamara <idankk86@gmail.com>
parents:
14943
diff
changeset
|
146 except ValueError: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25947
diff
changeset
|
147 raise error.Abort(_('invalid value %r for option %s, ' |
17712
c4717f44c1f1
fancyopts: don't show a traceback on invalid integer values
Idan Kamara <idankk86@gmail.com>
parents:
14943
diff
changeset
|
148 'expected int') % (val, opt)) |
5638
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
149 elif t is type(''): |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
150 state[name] = val |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
151 elif t is type([]): |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
152 state[name].append(val) |
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
153 elif t is type(None) or t is type(False): |
29947
e1f0ec0b7d2d
flags: allow specifying --no-boolean-flag on the command line (BC)
Augie Fackler <augie@google.com>
parents:
26587
diff
changeset
|
154 state[name] = boolval |
209 | 155 |
5638
a9b7e425674f
fancyopts: lots of cleanups
Matt Mackall <mpm@selenic.com>
parents:
5093
diff
changeset
|
156 # return unparsed args |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
157 return args |