def _PromptForScopeList(self, ambiguous_refs, attribute, resource_type, choice_resources, raise_on_prompt_failure): """Prompt to resolve abiguous resources. Either returns str or throws.""" # targetInstances -> target instances resource_name = utils.CamelCaseToOutputFriendly(resource_type) # Resource names should be surrounded by brackets while choices should not names = ['[{0}]'.format(name) for name, _ in ambiguous_refs] # Print deprecation state for choices. choice_names = [] for choice_resource in choice_resources: deprecated = choice_resource.deprecated if deprecated: choice_name = '{0} ({1})'.format(choice_resource.name, deprecated.state) else: choice_name = choice_resource.name choice_names.append(choice_name) title = utils.ConstructList( 'For the following {0}:'.format(resource_name), names) idx = console_io.PromptChoice(options=choice_names, message='{0}choose a {1}:'.format( title, attribute)) if idx is None: raise_on_prompt_failure() else: return choice_resources[idx].name
def PromptForScope(self, ambiguous_refs, attribute, service, resource_type, flag_name, prefix_filter): """Prompts the user to resolve abiguous resources.""" # targetInstances -> target instances resource_name = utils.CamelCaseToOutputFriendly(resource_type) # Resource names should be surrounded by brackets while choices should not names = ['[{0}]'.format(name) for name, _ in ambiguous_refs] choice_resources = self.FetchChoiceResources(attribute, service, flag_name, prefix_filter) # Print deprecation state for choices. choice_names = [] for choice_resource in choice_resources: deprecated = choice_resource.deprecated if deprecated: choice_name = '{0} ({1})'.format(choice_resource.name, deprecated.state) else: choice_name = choice_resource.name choice_names.append(choice_name) title = utils.ConstructList( 'For the following {0}:'.format(resource_name), names) idx = console_io.PromptChoice(options=choice_names, message='{0}choose a {1}:'.format( title, attribute)) if idx is None: raise exceptions.ToolException( 'Unable to prompt. Specify the [{0}] flag.'.format(flag_name)) choice_resource = choice_resources[idx] for _, resource_ref in ambiguous_refs: setattr(resource_ref, attribute, choice_resource.name)
def _PromptDidYouMeanScope(self, ambiguous_refs, attribute, resource_type, suggested_resource, raise_on_prompt_failure): """Prompts "did you mean <scope>". Returns str or None, or raises.""" # targetInstances -> target instances resource_name = utils.CamelCaseToOutputFriendly(resource_type) names = ['[{0}]'.format(name) for name, _ in ambiguous_refs] message = 'Did you mean {0} [{1}] for {2}: [{3}]?'.format( attribute, suggested_resource, resource_name, names) try: if console_io.PromptContinue(message=message, default=True, throw_if_unattended=True): return suggested_resource else: return None except console_io.UnattendedPromptError: raise_on_prompt_failure()