import getpass


def _get_value_from_prompt(title, confirm=False):
    """
    Retrieve a string value from a prompt on standard input. User input
    is not echoed to standard output, making it suitable for password-style
    user input.

    :param str title: Text preceding the argument prompt on the cli. For
        example, if "password" is used, the prompt on the cli would be
        "Enter password:".
    :param bool confirm: whether or not to do a confirmation prompt to
        ensure that the user enters the same value twice for the argument
    :return: value read from the prompt
    :rtype: str
    """
    while True:
        while True:
            value = getpass.getpass("Enter {}:".format(title))
            if not value:
                print("Value cannot be empty. Try again.")
            else:
                break
        confirm_value = getpass.getpass("Confirm {}:".format(title)) \
            if confirm else value
        if value != confirm_value:
            print("Values for {} do not match. Try again.".format(title))
        else:
            break
    return value