How to use the knack.prompting.prompt_choice_list function in knack

To help you get started, we’ve selected a few knack 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 microsoft / knack / tests / test_prompting.py View on Github external
def test_prompt_choice_list(self, _):
        a_list = ['red', 'blue', 'yellow', 'green']
        with mock.patch('knack.prompting._input', return_value='3'):
            actual_result = prompt_choice_list('What is your favourite color?', a_list)
            self.assertEqual(2, actual_result)
github microsoft / knack / tests / test_prompting.py View on Github external
def test_prompt_choice_list_question_no_help_string(self, _):
        a_list = ['red', 'blue', 'yellow', 'green']
        with mock.patch('logging.Logger.warning') as mock_log_warn:
            with self.assertRaises(StopIteration):
                with mock.patch('knack.prompting._input', side_effect=['?']):
                    prompt_choice_list('What is your favourite color?', a_list)
            mock_log_warn.assert_called_once_with('Valid values are %s', mock.ANY)
github Azure / azure-cli / src / azure-cli / azure / cli / command_modules / appservice / azure_devops_build_interactive.py View on Github external
def _select_functionapp(self):
        self.logger.info("Retrieving functionapp names.")
        functionapps = list_function_app(self.cmd)
        functionapp_names = sorted([functionapp.name for functionapp in functionapps])
        if not functionapp_names:
            raise CLIError("You do not have any existing function apps associated with this account subscription.{ls}"
                           "1. Please make sure you are logged into the right azure account by "
                           "running 'az account show' and checking the user.{ls}"
                           "2. If you are logged in as the right account please check the subscription you are using. "
                           "Run 'az account show' and view the name.{ls}"
                           "   If you need to set the subscription run "
                           "'az account set --subscription '{ls}"
                           "3. If you do not have a function app please create one".format(ls=os.linesep))
        choice_index = prompt_choice_list('Please select the target function app: ', functionapp_names)
        functionapp = [functionapp for functionapp in functionapps
                       if functionapp.name == functionapp_names[choice_index]][0]
        self.logger.info("Selected functionapp %s", functionapp.name)
        return functionapp
github Azure / azure-cli / src / azure-cli / azure / cli / command_modules / appservice / azure_devops_build_interactive.py View on Github external
def _select_project(self):
        projects = self.adbp.list_projects(self.organization_name)
        if projects.count > 0:
            project_names = sorted([project.name for project in projects.value])
            choice_index = prompt_choice_list('Please select your project: ', project_names)
            project = [project for project in projects.value if project.name == project_names[choice_index]][0]
            self.project_name = project.name
        else:
            self.logger.warning("There are no existing projects in this organization. "
                                "You need to create a new project.")
            self._create_project()
github Azure / azure-cli / src / azure-cli / azure / cli / command_modules / appservice / azure_devops_build_interactive.py View on Github external
def _create_organization(self):
        self.logger.info("Starting process to create a new Azure DevOps organization")
        regions = self.adbp.list_regions()
        region_names = sorted([region.display_name for region in regions.value])
        self.logger.info("The region for an Azure DevOps organization is where the organization will be located. "
                         "Try locate it near your other resources and your location")
        choice_index = prompt_choice_list('Please select a region for the new organization: ', region_names)
        region = [region for region in regions.value if region.display_name == region_names[choice_index]][0]

        while True:
            organization_name = prompt("Please enter a name for your new organization: ")
            new_organization = self.adbp.create_organization(organization_name, region.name)
            if new_organization.valid is False:
                self.logger.warning(new_organization.message)
                self.logger.warning("Note: all names must be globally unique")
            else:
                break

        self.organization_name = new_organization.name
github Azure / azure-cli-extensions / src / mesh / azext_mesh / custom.py View on Github external
result = OrderedDict()
    no_tty = False
    for param_name in prompt_list:
        param = missing_parameters[param_name]
        param_type = param.get('type', 'string')
        description = 'Missing description'
        metadata = param.get('metadata', None)
        if metadata is not None:
            description = metadata.get('description', description)
        allowed_values = param.get('allowedValues', None)

        prompt_str = "Please provide {} value for '{}' (? for help): ".format(param_type, param_name)
        while True:
            if allowed_values is not None:
                try:
                    ix = prompt_choice_list(prompt_str, allowed_values, help_string=description)
                    result[param_name] = allowed_values[ix]
                except NoTTYException:
                    result[param_name] = None
                    no_tty = True
                break
            elif param_type == 'securestring':
                try:
                    value = prompt_pass(prompt_str, help_string=description)
                except NoTTYException:
                    value = None
                    no_tty = True
                result[param_name] = value
                break
            elif param_type == 'int':
                try:
                    int_value = prompt_int(prompt_str, help_string=description)
github Azure / azure-cli / src / azure-cli / azure / cli / command_modules / appservice / azure_devops_build_interactive.py View on Github external
def _select_organization(self):
        organizations = self.adbp.list_organizations()
        organization_names = sorted([organization.accountName for organization in organizations.value])
        if not organization_names:
            self.logger.warning("There are no existing organizations, you need to create a new organization.")
            self._create_organization()
            self.created_organization = True
        else:
            choice_index = prompt_choice_list('Please choose the organization: ', organization_names)
            organization_match = [organization for organization in organizations.value
                                  if organization.accountName == organization_names[choice_index]][0]
            self.organization_name = organization_match.accountName
github Azure / azure-cli / src / azure-cli / azure / cli / command_modules / appservice / azure_devops_build_interactive.py View on Github external
def check_scenario(self):
        if self.repository_name:
            self.scenario = 'AZURE_DEVOPS'
        elif self.github_pat or self.github_repository:
            self.scenario = 'GITHUB_INTEGRATION'
        else:
            choice_index = prompt_choice_list(
                'Please choose Azure function source code location: ',
                SUPPORTED_SOURCECODE_LOCATIONS
            )
            self.scenario = SUPPORTED_SCENARIOS[choice_index]
        return self.scenario