Skip to content

Commit

Permalink
decreasing ask complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
jaesivsm committed Dec 1, 2016
1 parent 30dd026 commit d5549be
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions install.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3
import os
import imp
from sys import stderr, path
from subprocess import Popen, PIPE
from argparse import ArgumentParser
Expand Down Expand Up @@ -45,20 +44,24 @@ def can_npm():
return bool(Popen(['which', 'npm'], stdout=PIPE).communicate()[0])


def _print_line_informations(choices, default):
if choices:
print('[%s]' % '/'.join([chc.upper() if chc == default
or choices[chc] == default else chc
for chc in choices]), end=' ')
if default not in {'', None}:
if choices and default not in choices:
for new_default, value in choices.items():
if value == default:
default = new_default
break
print('(default: %r)' % default, end=' ')


def ask(text, choices=[], default=None, cast=None):
while True:
print(text, end=' ')
if choices:
print('[%s]' % '/'.join([chc.upper() if chc == default
or choices[chc] == default else chc
for chc in choices]), end=' ')
if default not in {'', None}:
if choices and default not in choices:
for new_default, value in choices.items():
if value == default:
default = new_default
break
print('(default: %r)' % default, end=' ')
_print_line_informations(choices, default)
print(':', end=' ')

result = input()
Expand Down

0 comments on commit d5549be

Please sign in to comment.