]> git.madduck.net Git - code/mailplate.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

fix template/mailfile detection while argument parsing
authormartin f. krafft <madduck@madduck.net>
Thu, 17 Jul 2008 11:11:16 +0000 (13:11 +0200)
committermartin f. krafft <madduck@madduck.net>
Thu, 17 Jul 2008 11:11:18 +0000 (13:11 +0200)
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.

mailplate

index 490ba8efe34cbe3f1e295b3d0d7242730348d87e..a26c8defeff779a3bb7d30bde863d402bcff1dfa 100755 (executable)
--- 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