aboutsummaryrefslogtreecommitdiff
blob: 035fe1b2d709c58f715fa18a5b737be54c7d2e0c (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
"""
A module to (non)interactively query the user for impure values
"""

import sys

from pomu.util.result import Result

def query(name, prompt=None, default=None):
    """
    Queries the impure world for name
    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()