Esempio n. 1
0
def _choose_names_manually(prompt_prefix: str = "") -> List[str]:
    """Manually input names for those without an installer.

    :param str prompt_prefix: string to prepend to prompt for domains

    :returns: list of provided names
    :rtype: `list` of `str`

    """
    code, input_ = display_util.input_text(
        prompt_prefix +
        "Please enter the domain name(s) you would like on your certificate "
        "(comma and/or space separated)",
        cli_flag="--domains",
        force_interactive=True)

    if code == display_util.OK:
        invalid_domains = {}
        retry_message = ""
        try:
            domain_list = internal_display_util.separate_list_input(input_)
        except UnicodeEncodeError:
            domain_list = []
            retry_message = (
                "Internationalized domain names are not presently "
                "supported.{0}{0}Would you like to re-enter the "
                "names?{0}").format(os.linesep)

        for i, domain in enumerate(domain_list):
            try:
                domain_list[i] = util.enforce_domain_sanity(domain)
            except errors.ConfigurationError as e:
                invalid_domains[domain] = str(e)

        if invalid_domains:
            retry_message = (
                "One or more of the entered domain names was not valid:"
                "{0}{0}").format(os.linesep)
            for invalid_domain, err in invalid_domains.items():
                retry_message = retry_message + "{1}: {2}{0}".format(
                    os.linesep, invalid_domain, err)
            retry_message = retry_message + (
                "{0}Would you like to re-enter the names?{0}").format(
                    os.linesep)

        if retry_message:
            # We had error in input
            retry = display_util.yesno(retry_message, force_interactive=True)
            if retry:
                return _choose_names_manually()
        else:
            return domain_list
    return []
Esempio n. 2
0
    def checklist(self,
                  message: str,
                  tags: List[str],
                  default: Optional[List[str]] = None,
                  cli_flag: Optional[str] = None,
                  force_interactive: bool = False,
                  **unused_kwargs: Any) -> Tuple[str, List[str]]:
        """Display a checklist.

        :param str message: Message to display to user
        :param list tags: `str` tags to select, len(tags) > 0
        :param default: default value to return (if one exists)
        :param str cli_flag: option used to set this value with the CLI
        :param bool force_interactive: True if it's safe to prompt the user
            because it won't cause any workflow regressions

        :returns: tuple of (`code`, `tags`) where
            `code` - str display exit code
            `tags` - list of selected tags
        :rtype: tuple

        """
        return_default = self._return_default(message, default, cli_flag,
                                              force_interactive)
        if return_default is not None:
            return OK, return_default

        while True:
            self._print_menu(message, tags)

            code, ans = self.input(
                "Select the appropriate numbers separated "
                "by commas and/or spaces, or leave input "
                "blank to select all options shown",
                force_interactive=True)

            if code == OK:
                if not ans.strip():
                    ans = " ".join(str(x) for x in range(1, len(tags) + 1))
                indices = util.separate_list_input(ans)
                selected_tags = self._scrub_checklist_input(indices, tags)
                if selected_tags:
                    return code, selected_tags
                self.outfile.write("** Error - Invalid selection **%s" %
                                   os.linesep)
                self.outfile.flush()
            else:
                return code, []
Esempio n. 3
0
 def _call(cls, input_):
     from certbot._internal.display.util import separate_list_input
     return separate_list_input(input_)