Console Functions (autotransform.util.console)
Utility methods for getting user input for AutoTransform.
- autotransform.util.console.choose_option(prompt: str, options: List[Tuple[T, List[str]]]) T
Prompts the user to choose one of a set of options using a string. User input is converted in to lower case.
- Parameters
prompt (str) – The prompt to give the user.
options (List[Tuple[T, List[str]]]) – The potential options to choose. The first value is the option, the second value is a list of potential aliases for the option.
- Returns
The selected option
- Return type
str
- autotransform.util.console.choose_options_from_list(prompt: str, options: List[Tuple[T, str]], min_choices: int = 1, max_choices: int = 1) List[T]
Prompts the user to choose one of a set of options using a list and having the user choose a number.
- Parameters
prompt (str) – The prompt for the user.
options (List[Tuple[T, str]]) – The options to choose from, where the first value in a Tuple is the option and the second value is the prompt for the list.
min_choices (int, optional) – The minimum number of selections to be made. Defaults to 1.
max_choices (int, optional) – The maximum number of selections to be made. Defaults to 1.
- Returns
The chosen options.
- Return type
List[T]
- autotransform.util.console.choose_yes_or_no(prompt: str) bool
Gives the user a yes or no prompt.
- Parameters
prompt (str) – The prompt to give to the user.
- Returns
If the user chose yes.
- Return type
bool
- autotransform.util.console.error(text: str) None
Prints a string of text as error to the console.
- Parameters
text (str) – The text to print.
- autotransform.util.console.get_str(prompt: str, secret: bool = False) str
Prompts the user to input a value.
- Parameters
prompt (str) – The prompt to give to the user
secret (bool, optional) – Whether to use getpass for input. Defaults to False.
- Returns
The input value.
- Return type
str
- autotransform.util.console.info(text: str) None
Prints a string of text as info to the console.
- Parameters
text (str) – The text to print.
- autotransform.util.console.input_int(prompt: str, min_val: Optional[int] = None, max_val: Optional[int] = None) int
Gets an integer input from the user within the specified range.
- Parameters
prompt (str) – The prompt to give the user.
min_val (Optional[int], optional) – The minimum acceptable value. Defaults to None.
max_val (Optional[int], optional) – The maximum acceptable value. Defaults to None.
- Returns
The integer specified by the user.
- Return type
int
- autotransform.util.console.input_ints(prompt: str, min_val: Optional[int] = None, max_val: Optional[int] = None, min_choices: int = 1, max_choices: int = 1) List[int]
Gets integers input from the user within the specified range.
- Parameters
prompt (str) – The prompt to give the user.
min_val (Optional[int], optional) – The minimum acceptable value. Defaults to None.
max_val (Optional[int], optional) – The maximum acceptable value. Defaults to None.
min_choices (int, optional) – The minimum number of selections to be made. Defaults to 1.
max_choices (int, optional) – The maximum number of selections to be made. Defaults to 1.
- Returns
The integers specified by the user.
- Return type
List[int]
- autotransform.util.console.input_string(prompt: str, name: str, previous: Optional[str] = None, default: Optional[str] = None, secret: bool = False) str
Prompts the user to input a value, or potentially use a previously input value/default value.
- Parameters
prompt (str) – The prompt to give to the user.
name (str) – The name of the value being prompted for.
previous (Optional[str], optional) – The previously input value. Defaults to None.
default (Optional[str], optional) – The default value. Defaults to None.
secret (bool, optional) – Whether to use getpass for inputs. Defaults to False.
- Returns
The value entered by the user.
- Return type
str