op = OP.OptionParser(
description = 'Generates files by filling in simple templates',
- usage = 'usage: %prog [-gl] FILE [COL,...=VAL,... ... | @FILE:COL,...] ...',
+ usage = 'usage: %prog {-l | -g TMPL} FILE [COL,...=VAL,... ... | @FILE:COL,...] ...',
version = 'Catacomb version @VERSION@')
+def cb_gen(opt, optstr, arg, op):
+ op.values.input = arg
+ op.values.mode = 'gen'
for short, long, kw in [
('-l', '--list', dict(
action = 'store_const', const = 'list', dest = 'mode',
help = 'list filenames generated')),
('-g', '--generate', dict(
- action = 'store', metavar = 'PATH', dest = 'input',
- help = 'generate output (default)'))]:
+ action = 'callback', metavar = 'TEMPLATE',
+ callback = cb_gen, type = 'string',
+ help = 'generate file(s) from TEMPLATE file'))]:
op.add_option(short, long, **kw)
-op.set_defaults(mode = 'gen')
+op.set_defaults(mode = 'what?')
opts, args = op.parse_args()
if len(args) < 1: op.error('missing FILE')
templ.subst(out, cs)
OS.rename(new, file)
else:
- raise Exception, 'What am I doing here?'
+ die('What am I doing here?')
###----- That's all, folks --------------------------------------------------