~mdw
/
tripe
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
keys/tripe-keys.in: Improve reporting of usage errors.
[tripe]
/
keys
/
tripe-keys.in
diff --git
a/keys/tripe-keys.in
b/keys/tripe-keys.in
index
47a4417
..
901e09b
100644
(file)
--- a/
keys/tripe-keys.in
+++ b/
keys/tripe-keys.in
@@
-344,8
+344,9
@@
Subcommands available:
args = commands.keys()
args.sort()
for c in args:
args = commands.keys()
args.sort()
for c in args:
- func, min, max, help = commands[c]
- print '%s %s' % (c, help)
+ try: func, min, max, help = commands[c]
+ except KeyError: die("unknown command `%s'" % c)
+ print '%s%s%s' % (c, help and ' ', help)
###--------------------------------------------------------------------------
### Commands: newmaster
###--------------------------------------------------------------------------
### Commands: newmaster
@@
-554,9
+555,6
@@
def cmd_mtu(args):
###--------------------------------------------------------------------------
### Main driver.
###--------------------------------------------------------------------------
### Main driver.
-## Exceptions.
-class UsageError (Exception): pass
-
commands = {'help': (cmd_help, 0, 1, ''),
'newmaster': (cmd_newmaster, 0, 0, ''),
'setup': (cmd_setup, 0, 0, ''),
commands = {'help': (cmd_help, 0, 1, ''),
'newmaster': (cmd_newmaster, 0, 0, ''),
'setup': (cmd_setup, 0, 0, ''),
@@
-604,10
+602,12
@@
def main(argv):
cmd_help([])
else:
c = argv[1]
cmd_help([])
else:
c = argv[1]
- func, min, max, help = commands[c]
+ try: func, min, max, help = commands[c]
+ except KeyError: die("unknown command `%s'" % c)
args = argv[2:]
args = argv[2:]
- if len(args) < min or (max > 0 and len(args) > max):
- raise UsageError, (c, help)
+ if len(args) < min or (max is not None and len(args) > max):
+ SYS.stderr.write('Usage: %s %s%s%s\n' % (quis, c, help and ' ', help))
+ SYS.exit(1)
func(args)
###----- That's all, folks --------------------------------------------------
func(args)
###----- That's all, folks --------------------------------------------------