]> git.phdru.name Git - mimedecode.git/commitdiff
Print more descriptive error messages
authorOleg Broytman <phd@phdru.name>
Thu, 30 Jan 2014 19:02:34 +0000 (23:02 +0400)
committerOleg Broytman <phd@phdru.name>
Thu, 30 Jan 2014 19:02:34 +0000 (23:02 +0400)
mimedecode.py

index 36468ecf3d581cd7e0cd80f4d58b1831c6cdf643..f46165b23936cf100e432c44640d0bf293496ac0 100755 (executable)
@@ -27,11 +27,13 @@ Broytman mimedecode.py version %s, %s
     if exit: sys.exit(0)
 
 
-def usage(code=0):
+def usage(code=0, errormsg=''):
     version(0)
     sys.stdout.write("""\
 Usage: %s [-h|--help] [-V|--version] [-cCDP] [-f charset] [-d header] [-p header:param] [-beit mask] [-o output_file] [input_file [output_file]]
 """ % me)
+    if errormsg:
+        sys.stderr.write(errormsg + '\n')
     sys.exit(code)
 
 
@@ -376,8 +378,8 @@ if __name__ == "__main__":
                 gopts.output_filename = '-'
                 outfile = sys.stdout
         elif la == 2:
-            if gopts.output_filename: # Too many output filenames
-                usage(1)
+            if gopts.output_filename:
+                usage(1, 'Too many output filenames')
             if (arguments[1] == '-'):
                 gopts.output_filename = '-'
                 outfile = sys.stdout
@@ -385,7 +387,7 @@ if __name__ == "__main__":
                 gopts.output_filename = arguments[1]
                 outfile = open(arguments[1], 'w')
     else:
-        usage(1)
+        usage(1, 'Too many arguments')
 
     gopts.outfile = outfile
     decode_file(infile)