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
OS.chdir(cwd)
if OS.path.exists('repos'): OS.rename('repos', 'repos.old')
OS.rename('tmp/repos', 'repos')
- if not FC.cmp('tmp/tripe-keys.conf', 'tripe-keys.conf'):
+ if not FC.cmp('tmp/tripe-keys.conf', 'tripe-keys.conf', False):
moan('configuration file changed: recommend running another update')
OS.rename('tmp/tripe-keys.conf', 'tripe-keys.conf')
rmtree('repos.old')
###--------------------------------------------------------------------------
### Main driver.
-## Exceptions.
-class UsageError (Exception): pass
-
commands = {'help': (cmd_help, 0, 1, ''),
'newmaster': (cmd_newmaster, 0, 0, ''),
'setup': (cmd_setup, 0, 0, ''),
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:]
- 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 --------------------------------------------------