From: martin f. krafft Date: Thu, 17 Jul 2008 11:11:16 +0000 (+0200) Subject: fix template/mailfile detection while argument parsing X-Git-Tag: mailplate-0.2~1 X-Git-Url: https://git.madduck.net/code/mailplate.git/commitdiff_plain/b6287ce4bbb2c7ca8d1056469fccf5eeb21e484c fix template/mailfile detection while argument parsing If template 'foo' is being used in a directory where ./foo exists, the argument parsing decides that ./foo must be the message to rewrite and clobbers it. Now there are more sanity checks in place, and I first try to determine the template, then the file. --- diff --git a/mailplate b/mailplate index 490ba8e..a26c8de 100755 --- a/mailplate +++ b/mailplate @@ -269,19 +269,27 @@ if options.debug: # parse the arguments for arg in args: if arg == '-': - # filename is -, so do nothing, since stdin/stdout are default - continue + infname = arg + outfname = arg + elif arg.find(os.path.sep) == -1 and os.access(os.path.join(TPATH, arg), os.R_OK): + if templname is not None: + err("template already specified (%s), unsure what to do with '%s'" + % (templname, arg)) + sys.exit(posix.EX_USAGE) + # argument references an existing template + templname = arg elif os.path.isfile(arg): + if infname is not None: + err("input file already specified (%s), unsure what to do with '%s'" + % (infname, arg)) + sys.exit(posix.EX_USAGE) # the file exists, so use it as in/out if read/writeable if os.access(arg, os.R_OK): infname = arg if os.access(arg, os.W_OK): outfname = arg - elif os.access(os.path.join(TPATH, arg), os.R_OK): - # argument referenced an existing template - templname = arg else: - err('unknown argument, and cannot find a template by this name: %s' % arg) + err('unknown argument: %s' % arg) sys.exit(posix.EX_USAGE) # sanity checks