]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
pretty up --help formatting 461/head
authorMike Koss <mckoss@startpad.org>
Mon, 13 Feb 2012 22:17:11 +0000 (14:17 -0800)
committerMike Koss <mckoss@startpad.org>
Thu, 5 Apr 2012 21:18:40 +0000 (14:18 -0700)
tornado/options.py

index feae3292cdf87d7a4ea9b2a8f2ed4ac22a37effe..5d20dcbf218d25600eec61d6f4f2f3cbfdba0881 100644 (file)
@@ -55,7 +55,9 @@ import logging
 import logging.handlers
 import re
 import sys
+import os
 import time
+import textwrap
 
 from tornado.escape import _unicode
 
@@ -165,21 +167,28 @@ def parse_config_file(path):
 def print_help(file=sys.stdout):
     """Prints all the command line options to stdout."""
     print >> file, "Usage: %s [OPTIONS]" % sys.argv[0]
-    print >> file, ""
-    print >> file, "Options:"
+    print >> file, "\nOptions:\n"
     by_group = {}
     for option in options.itervalues():
         by_group.setdefault(option.group_name, []).append(option)
 
     for filename, o in sorted(by_group.items()):
         if filename:
-            print >> file, filename
+            print >> file, "\n%s options:\n" % os.path.normpath(filename)
         o.sort(key=lambda option: option.name)
         for option in o:
             prefix = option.name
             if option.metavar:
                 prefix += "=" + option.metavar
-            print >> file, "  --%-30s %s" % (prefix, option.help or "")
+            description = option.help or ""
+            if option.default is not None and option.default != '':
+                description += " (default %s)" % option.default
+            lines = textwrap.wrap(description, 79 - 35)
+            if len(prefix) > 30:
+                lines.insert(0, '')
+            print >> file, "  --%-30s %s" % (prefix, lines[0])
+            for line in lines[1:]:
+                print >> file, "%-34s %s" % (' ', line)
     print >> file