[pypy-commit] creflect default: Make the second argument to 'creflect' optional (defaults to the first

arigo noreply at buildbot.pypy.org
Sat Nov 29 22:32:45 CET 2014


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r123:62e314b00876
Date: 2014-11-29 18:24 +0100
http://bitbucket.org/cffi/creflect/changeset/62e314b00876/

Log:	Make the second argument to 'creflect' optional (defaults to the
	first argument with extension '.c').

diff --git a/creflect/cmdline.py b/creflect/cmdline.py
--- a/creflect/cmdline.py
+++ b/creflect/cmdline.py
@@ -1,7 +1,7 @@
 """Usage:
 
-    creflect  [options]  input.crx  output.c
-    creflect  [options]  -i  input.h  output.c
+    creflect  [options]  input.crx  [output.c]
+    creflect  [options]  -i  input.h  [output.c]
 
 Read the input file and expand the CREFLECT sections in it
 into regular C code.  Write the result to 'output.c'.
@@ -62,9 +62,13 @@
             print 'CReflect %s' % __version__
             return 0
     #
-    if len(args) != 2:
-        return error("expected exactly 2 arguments, got %d" % (len(args),))
-    inputfile, outputfile = args
+    if len(args) == 1:
+        inputfile, = args
+        outputfile = os.path.splitext(inputfile)[0] + '.c'
+    elif len(args) == 2:
+        inputfile, outputfile = args
+    else:
+        return error("expected 1 or 2 arguments, got %d" % (len(args),))
     if inputfile == outputfile:
         return error("not overwriting the file %r" % (inputfile,))
     #


More information about the pypy-commit mailing list