blob: d9dc09e693f8aeaf6e76e16caae29c5ab0549d49 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
"""
A module to (non)interactively query the user for impure values
"""
from pomu.util.result import Result
def query(name, prompt=None, default=None):
"""
Queries the impure world for name
Parameters:
name - the name
prompt - prompt text
default - default value used for errors, forced non-interactive etc.
TODO: non-interactive
"""
if not prompt:
prompt = 'Please enter ' + name
if default: prompt += ' ({})'.format(default)
prompt += ' > '
res = None
try:
res = input(prompt)
except EOFError: pass
if not res:
res = default
if not res:
return Result.Err('No {} or default provided'.format(name))
return Result.Ok()
|