##// END OF EJS Templates
hg help improvements...
mpm@selenic.com -
r293:11d64332 default
parent child Browse files
Show More
@@ -77,6 +77,17 b' def help(ui, cmd=None):'
77 try:
77 try:
78 i = find(cmd)
78 i = find(cmd)
79 ui.write("%s\n\n" % i[2])
79 ui.write("%s\n\n" % i[2])
80
81 if i[1]:
82 for s, l, d, c in i[1]:
83 opt=' '
84 if s: opt = opt + '-' + s + ' '
85 if l: opt = opt + '--' + l + ' '
86 if d: opt = opt + '(' + str(d) + ')'
87 ui.write(opt, "\n")
88 if c: ui.write(' %s\n' % c)
89 ui.write("\n")
90
80 ui.write(i[0].__doc__, "\n")
91 ui.write(i[0].__doc__, "\n")
81 except UnknownCommand:
92 except UnknownCommand:
82 ui.warn("hg: unknown command %s\n" % cmd)
93 ui.warn("hg: unknown command %s\n" % cmd)
@@ -603,7 +614,12 b' def dispatch(args):'
603 signal.signal(signal.SIGTERM, catchterm)
614 signal.signal(signal.SIGTERM, catchterm)
604
615
605 cmdoptions = {}
616 cmdoptions = {}
606 args = fancyopts.fancyopts(args, i[1], cmdoptions, i[2])
617 try:
618 args = fancyopts.fancyopts(args, i[1], cmdoptions, i[2])
619 except fancyopts.getopt.GetoptError, inst:
620 u.warn("hg %s: %s\n" % (cmd, inst))
621 help(u, cmd)
622 sys.exit(-1)
607
623
608 if cmd not in norepo.split():
624 if cmd not in norepo.split():
609 repo = hg.repository(ui = u)
625 repo = hg.repository(ui = u)
@@ -627,7 +643,8 b' def dispatch(args):'
627 tb = traceback.extract_tb(sys.exc_info()[2])
643 tb = traceback.extract_tb(sys.exc_info()[2])
628 if len(tb) > 2: # no
644 if len(tb) > 2: # no
629 raise
645 raise
630 raise
646 u.debug(inst, "\n")
631 u.warn("%s: invalid arguments\n" % i[0].__name__)
647 u.warn("%s: invalid arguments\n" % i[0].__name__)
632 u.warn("syntax: %s\n" % i[2])
648 help(u, cmd)
633 sys.exit(-1)
649 sys.exit(-1)
650
@@ -6,48 +6,25 b' def fancyopts(args, options, state, synt'
6 map={}
6 map={}
7 dt={}
7 dt={}
8
8
9 def help(state, opt, arg, options=options, syntax=syntax):
10 print "Usage: ", syntax
11
12 for s, l, d, c in options:
13 opt=' '
14 if s: opt = opt + '-' + s + ' '
15 if l: opt = opt + '--' + l + ' '
16 if d: opt = opt + '(' + str(d) + ')'
17 print opt
18 if c: print ' %s' % c
19 sys.exit(0)
20
21 if len(args) < minlen:
22 help(state, None, args)
23
24 options=[('h', 'help', help, 'Show usage info')] + options
25
26 for s, l, d, c in options:
9 for s, l, d, c in options:
27 map['-'+s] = map['--'+l]=l
10 map['-'+s] = map['--'+l]=l
28 state[l] = d
11 state[l] = d
29 dt[l] = type(d)
12 dt[l] = type(d)
30 if not d is None and not type(d) is type(help): s, l=s+':', l+'='
13 if not d is None and not callable(d): s, l=s+':', l+'='
31 if s: short = short + s
14 if s: short = short + s
32 if l: long.append(l)
15 if l: long.append(l)
33
16
34 if os.environ.has_key("HG_OPTS"):
17 if os.environ.has_key("HG_OPTS"):
35 args = os.environ["HG_OPTS"].split() + args
18 args = os.environ["HG_OPTS"].split() + args
36
19
37 try:
20 opts, args = getopt.getopt(args, short, long)
38 opts, args = getopt.getopt(args, short, long)
39 except getopt.GetoptError:
40 help(state, None, args)
41 sys.exit(-1)
42
21
43 for opt, arg in opts:
22 for opt, arg in opts:
44 if dt[map[opt]] is type(help): state[map[opt]](state,map[opt],arg)
23 if dt[map[opt]] is type(fancyopts): state[map[opt]](state,map[opt],arg)
45 elif dt[map[opt]] is type(1): state[map[opt]] = int(arg)
24 elif dt[map[opt]] is type(1): state[map[opt]] = int(arg)
46 elif dt[map[opt]] is type(''): state[map[opt]] = arg
25 elif dt[map[opt]] is type(''): state[map[opt]] = arg
47 elif dt[map[opt]] is type([]): state[map[opt]].append(arg)
26 elif dt[map[opt]] is type([]): state[map[opt]].append(arg)
48 elif dt[map[opt]] is type(None): state[map[opt]] = 1
27 elif dt[map[opt]] is type(None): state[map[opt]] = 1
49
28
50 del state["help"]
51
52 return args
29 return args
53
30
General Comments 0
You need to be logged in to leave comments. Login now