def prompt_for_external_auth_url(existing_url): if existing_url == '': existing_url = 'none' new_url = read_input( "URL to external Candid server [default={}]: ".format(existing_url)) if new_url == '': new_url = existing_url return new_url
def required_prompt(prompt, help_text=None): """Prompt for required input.""" value = None while not value or value == "help": value = read_input(prompt) if value == "help": if help_text: print_msg(help_text) return value
def _get_or_prompt(options, option, message, replace_none=False): """Return a config option either from command line or interactive input.""" config = options.get(option) if config is None: config = read_input(message) if replace_none and config == 'none': config = '' if config is None: config = '' return config
def prompt_for_maas_url(): """Prompt for the MAAS URL.""" default_url = get_default_url() url = None while not url or url == "help": url = read_input("MAAS URL [default=%s]: " % default_url) if not url: url = default_url if url == "help": print_msg( 'URL that MAAS should use for communicate from the nodes ' 'to MAAS and other controllers of MAAS.') return url
def _pick_service(services): print('Please select which service to register this MAAS as:\n') services_list = sorted( (service['name'], service['pending']) for service in services.values()) for idx, (name, pending) in enumerate(services_list, 1): print(' {:3} - {} {}'.format(idx, name, '(pending)' if pending else '')) print() idx = read_input('Select service index: ') try: service_name = services_list[int(idx) - 1][0] except (ValueError, IndexError): raise CommandError('Invalid index') return services[service_name]
def _pick_service(services): print("Please select which service to register this MAAS as:\n") services_list = sorted( (service["name"], service["pending"]) for service in services.values()) for idx, (name, pending) in enumerate(services_list, 1): print(" {:3} - {} {}".format(idx, name, "(pending)" if pending else "")) print() idx = read_input("Select service index: ") try: service_name = services_list[int(idx) - 1][0] except (ValueError, IndexError): raise CommandError("Invalid index") return services[service_name]
def required_prompt(title, help_text=None, default=None): """Prompt for required input.""" value = None if default is not None: default_text = f" [default={default}]" else: default_text = "" prompt = f"{title}{default_text}: " while not value or value == "help": value = read_input(prompt) if not value and default is not None: value = default if value == "help": if help_text: print_msg(help_text) return value
def prompt_for_ssh_import(): """Prompt user for protocal and user-id to import SSH keys.""" return read_input( "Import SSH keys [] (lp:user-id or gh:user-id): ")
def prompt_for_email(): """Prompt user for an email.""" email = read_input("Email: ") if not email: raise EmptyEmail("You must input an email or provide it with --email") return email
def prompt_for_username(): username = read_input("Username: "******"You must input a username or " "provide it with --username.") return username