[yt-svn] commit/yt: ngoldbaum: Subclassing argparse.ArgumentParser to get a better error message. Closes #596.
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Fri Jun 21 13:21:33 PDT 2013
1 new commit in yt:
https://bitbucket.org/yt_analysis/yt/commits/3a638f82a37e/
Changeset: 3a638f82a37e
Branch: yt
User: ngoldbaum
Date: 2013-06-21 21:13:12
Summary: Subclassing argparse.ArgumentParser to get a better error message. Closes #596.
See http://stackoverflow.com/questions/4561580/how-to-let-the-parser-print-help-message-rather-than-error-and-exit
Affected #: 1 file
diff -r 2c15a177fc684678b9c09120a6cf3b08ddb19457 -r 3a638f82a37eb6a647ca4cda18446d94a055f221 yt/startup_tasks.py
--- a/yt/startup_tasks.py
+++ b/yt/startup_tasks.py
@@ -98,7 +98,17 @@
if param == "loglevel": # special case
mylog.setLevel(int(val))
-parser = argparse.ArgumentParser(description = 'yt command line arguments')
+class YTParser(argparse.ArgumentParser):
+ def error(self, message):
+ """error(message: string)
+
+ Prints a help message that is more detailed than the argparse default
+ and then exits.
+ """
+ self.print_help(sys.stderr)
+ self.exit(2, '%s: error: %s\n' % (self.prog, message))
+
+parser = YTParser(description = 'yt command line arguments')
parser.add_argument("--config", action=SetConfigOption,
help = "Set configuration option, in the form param=value")
parser.add_argument("--paste", action=SetExceptionHandling,
Repository URL: https://bitbucket.org/yt_analysis/yt/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the yt-svn
mailing list