Skip to content

Commit

Permalink
use optparse choices to deal with invalid scheme selection.
Browse files Browse the repository at this point in the history
  • Loading branch information
schettino72 committed Oct 13, 2013
1 parent 1111aec commit 214d736
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 5 additions & 3 deletions ansi2html/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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__,
Expand Down Expand Up @@ -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()

Expand Down
1 change: 0 additions & 1 deletion ansi2html/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down

0 comments on commit 214d736

Please sign in to comment.