forked from charleso/git-cc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitcc
executable file
·48 lines (43 loc) · 1.35 KB
/
gitcc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
import sys, inspect
from optparse import OptionParser
import rebase, checkin, init, sync, reset, tag, update
commands = [
init, rebase, checkin, sync, reset, tag, update
]
def main():
args = sys.argv[1:]
for cmd in commands:
if args and cmd.__name__ == args[0]:
return invoke(cmd, args)
usage()
def invoke(cmd, args):
_args, _, _, defaults = inspect.getargspec(cmd.main)
defaults = defaults if defaults else []
diff = len(_args) - len(defaults)
_args = _args[diff:]
parser = OptionParser(description=cmd.__doc__)
for (name, default) in zip(_args, defaults):
option = {
'default': default,
'help': cmd.ARGS[name],
'dest': name,
}
if default == False:
option['action'] = "store_true"
name = name.replace('_', '-')
parser.add_option('--' + name, **option)
(options, args) = parser.parse_args(args[1:])
if len(args) < diff:
parser.error("incorrect number of arguments")
for name in _args:
args.append(getattr(options, name))
cmd.main(*args)
def usage():
print('usage: gitcc COMMAND [ARGS]\n')
width = 11
for cmd in commands:
print(' %s %s' % (cmd.__name__.ljust(width), cmd.__doc__.split('\n')[0]))
sys.exit(2)
if __name__ == '__main__':
main()