From 214d73609ff0e0dd645778dbbc0392cd340f8df5 Mon Sep 17 00:00:00 2001 From: schettino72 Date: Sun, 13 Oct 2013 14:32:26 +0800 Subject: [PATCH] use optparse choices to deal with invalid scheme selection. --- ansi2html/converter.py | 8 +++++--- ansi2html/style.py | 1 - 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ansi2html/converter.py b/ansi2html/converter.py index ba8c3e5..88f40b7 100755 --- a/ansi2html/converter.py +++ b/ansi2html/converter.py @@ -29,7 +29,7 @@ except ImportError: from ordereddict import OrderedDict -from ansi2html.style import get_styles +from ansi2html.style import get_styles, SCHEME import six from six.moves import map from six.moves import zip @@ -386,6 +386,7 @@ def main(): $ task burndown | ansi2html > burndown.html """ + scheme_names = sorted(six.iterkeys(SCHEME)) version_str = pkg_resources.get_distribution('ansi2html').version parser = optparse.OptionParser( usage=main.__doc__, @@ -432,8 +433,9 @@ def main(): help="Specify output encoding") parser.add_option( '-s', '--scheme', dest='scheme', metavar='SCHEME', - default='ansi2html', - help="Specify color palette scheme [ansi2html, xterm, xterm-bright]") + default='ansi2html', choices=scheme_names, + help=("Specify color palette scheme. Default: %%default. Choices: %s" + % scheme_names)) opts, args = parser.parse_args() diff --git a/ansi2html/style.py b/ansi2html/style.py index 06cddb1..dcc778c 100644 --- a/ansi2html/style.py +++ b/ansi2html/style.py @@ -76,7 +76,6 @@ def get_styles(dark_bg=True, scheme='ansi2html'): ] # set palette - assert scheme in SCHEME pal = SCHEME[scheme] for _index in range(8): css.append(Rule('.ansi3%s' % _index, color=pal[_index]))