How to use the questionary.prompt.PromptParameterException function in questionary

To help you get started, we’ve selected a few questionary examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tmbo / questionary / tests / test_prompt.py View on Github external
def test_missing_name():
    with pytest.raises(PromptParameterException):
        prompt(
            [
                {
                    "type": "confirm",
                    "message": "Do you want to continue?",
                    "default": True,
                }
github tmbo / questionary / tests / test_prompt.py View on Github external
def test_missing_message():
    with pytest.raises(PromptParameterException):
        prompt([{"type": "confirm", "name": "continue", "default": True}])
github tmbo / questionary / questionary / prompt.py View on Github external
def __init__(self, message, errors=None):
        # Call the base class constructor with the parameters it needs
        super(PromptParameterException, self).__init__(
            "You must provide a `%s` value" % message, errors
        )
github tmbo / questionary / questionary / prompt.py View on Github external
patch_stdout: bool = False,
    true_color: bool = False,
    kbi_msg: Text = DEFAULT_KBI_MESSAGE,
    **kwargs
):
    """Prompt the user for input on all the questions."""

    if isinstance(questions, dict):
        questions = [questions]

    answers = answers or {}

    for question_config in questions:
        # import the question
        if "type" not in question_config:
            raise PromptParameterException("type")
        if "name" not in question_config:
            raise PromptParameterException("name")

        choices = question_config.get("choices")
        if choices is not None and callable(choices):
            question_config["choices"] = choices(answers)

        _kwargs = kwargs.copy()
        _kwargs.update(question_config)

        _type = _kwargs.pop("type")
        _filter = _kwargs.pop("filter", None)
        name = _kwargs.pop("name")
        when = _kwargs.pop("when", None)

        if true_color:
github tmbo / questionary / questionary / prompt.py View on Github external
if callable(question_config.get("default")):
                _kwargs["default"] = question_config["default"](answers)

            create_question_func = prompt_by_name(_type)

            if not create_question_func:
                raise ValueError(
                    "No question type '{}' found. "
                    "Known question types are {}."
                    "".format(_type, ", ".join(AVAILABLE_PROMPTS))
                )

            missing_args = list(utils.missing_arguments(create_question_func, _kwargs))
            if missing_args:
                raise PromptParameterException(missing_args[0])

            question = create_question_func(**_kwargs)

            answer = question.unsafe_ask(patch_stdout)

            if answer is not None:
                if _filter:
                    try:
                        answer = _filter(answer)
                    except Exception as e:
                        raise ValueError(
                            "Problem processing 'filter' of {} "
                            "question: {}".format(name, e)
                        )
                answers[name] = answer
        except KeyboardInterrupt:
github tmbo / questionary / questionary / prompt.py View on Github external
kbi_msg: Text = DEFAULT_KBI_MESSAGE,
    **kwargs
):
    """Prompt the user for input on all the questions."""

    if isinstance(questions, dict):
        questions = [questions]

    answers = answers or {}

    for question_config in questions:
        # import the question
        if "type" not in question_config:
            raise PromptParameterException("type")
        if "name" not in question_config:
            raise PromptParameterException("name")

        choices = question_config.get("choices")
        if choices is not None and callable(choices):
            question_config["choices"] = choices(answers)

        _kwargs = kwargs.copy()
        _kwargs.update(question_config)

        _type = _kwargs.pop("type")
        _filter = _kwargs.pop("filter", None)
        name = _kwargs.pop("name")
        when = _kwargs.pop("when", None)

        if true_color:
            _kwargs["color_depth"] = ColorDepth.TRUE_COLOR