Merge remote-tracking branch 'mckoss/feature/pretty-help' into merge
This commit is contained in:
commit
fde872df39
tornado
|
@ -55,7 +55,9 @@ import logging
|
||||||
import logging.handlers
|
import logging.handlers
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
import time
|
import time
|
||||||
|
import textwrap
|
||||||
|
|
||||||
from tornado.escape import _unicode
|
from tornado.escape import _unicode
|
||||||
|
|
||||||
|
@ -165,21 +167,28 @@ def parse_config_file(path):
|
||||||
def print_help(file=sys.stdout):
|
def print_help(file=sys.stdout):
|
||||||
"""Prints all the command line options to stdout."""
|
"""Prints all the command line options to stdout."""
|
||||||
print >> file, "Usage: %s [OPTIONS]" % sys.argv[0]
|
print >> file, "Usage: %s [OPTIONS]" % sys.argv[0]
|
||||||
print >> file, ""
|
print >> file, "\nOptions:\n"
|
||||||
print >> file, "Options:"
|
|
||||||
by_group = {}
|
by_group = {}
|
||||||
for option in options.itervalues():
|
for option in options.itervalues():
|
||||||
by_group.setdefault(option.group_name, []).append(option)
|
by_group.setdefault(option.group_name, []).append(option)
|
||||||
|
|
||||||
for filename, o in sorted(by_group.items()):
|
for filename, o in sorted(by_group.items()):
|
||||||
if filename:
|
if filename:
|
||||||
print >> file, filename
|
print >> file, "\n%s options:\n" % os.path.normpath(filename)
|
||||||
o.sort(key=lambda option: option.name)
|
o.sort(key=lambda option: option.name)
|
||||||
for option in o:
|
for option in o:
|
||||||
prefix = option.name
|
prefix = option.name
|
||||||
if option.metavar:
|
if option.metavar:
|
||||||
prefix += "=" + 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 or len(lines) == 0:
|
||||||
|
lines.insert(0, '')
|
||||||
|
print >> file, " --%-30s %s" % (prefix, lines[0])
|
||||||
|
for line in lines[1:]:
|
||||||
|
print >> file, "%-34s %s" % (' ', line)
|
||||||
print >> file
|
print >> file
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue