[Jython-checkins] jython: Make output on command line errors more consistent with CPython.

nicholas.riley jython-checkins at python.org
Wed Mar 21 21:10:02 CET 2012


http://hg.python.org/jython/rev/71ab84f0b096
changeset:   6456:71ab84f0b096
user:        Nicholas Riley <njriley at illinois.edu>
date:        Wed Mar 21 16:08:57 2012 -0400
summary:
  Make output on command line errors more consistent with CPython.

files:
  src/org/python/util/jython.java |  21 ++++++++++++---------
  1 files changed, 12 insertions(+), 9 deletions(-)


diff --git a/src/org/python/util/jython.java b/src/org/python/util/jython.java
--- a/src/org/python/util/jython.java
+++ b/src/org/python/util/jython.java
@@ -68,6 +68,7 @@
         "file     : program read from script file\n" +
         "-        : program read from stdin (default; interactive mode if a tty)\n" +
         "arg ...  : arguments passed to program in sys.argv[1:]\n" +
+        "\n" +
         "Other environment variables:\n" +
         "JYTHONPATH: '" + File.pathSeparator +
         "'-separated list of directories prefixed to the default module\n" +
@@ -143,8 +144,11 @@
                 System.err.println("Jython " + Version.PY_VERSION);
                 System.exit(0);
             }
-            if (!opts.runCommand && !opts.runModule) {
+            if (opts.help) {
                 System.err.println(usage);
+            } else if (!opts.runCommand && !opts.runModule) {
+                System.err.print(usageHeader);
+                System.err.println("Try `jython -h' for more information.");
             }
 
             int exitcode = opts.help ? 0 : -1;
@@ -400,6 +404,11 @@
             // continue
         }
     }
+    
+    private boolean argumentExpected(String arg) {
+        System.err.println("Argument expected for the " + arg + " option");
+        return false;
+    }
 
     public boolean parse(String[] args) {
         int index = 0;
@@ -444,10 +453,7 @@
                 } else if ((index + 1) < args.length) {
                     command = args[++index];
                 } else {
-                    System.err.println("Argument expected for the -c option");
-                    System.err.print(jython.usageHeader);
-                    System.err.println("Try `jython -h' for more information.");
-                    return false;
+                    return argumentExpected(arg);
                 }
                 if (!fixInteractive) {
                     interactive = false;
@@ -489,10 +495,7 @@
                 } else if ((index + 1) < args.length) {
                     moduleName = args[++index];
                 } else {
-                    System.err.println("Argument expected for the -m option");
-                    System.err.print(jython.usageHeader);
-                    System.err.println("Try `jython -h' for more information.");
-                    return false;
+                    return argumentExpected(arg);
                 }
                 if (!fixInteractive) {
                     interactive = false;

-- 
Repository URL: http://hg.python.org/jython


More information about the Jython-checkins mailing list