ask_lib package#
Submodules#
ask_lib.ask module#
- ask_lib.ask.ask(message, default_option=AskResult.YES, flag: AskFlag | None = None) bool#
Ask user’s confirmation about an action.
- Parameters:
message (str) – The question that will be asked to the user.
default_option (str, optional) – Default response if users does not give a valid response. Must be AskResult.YES, or AskResult.NO.
flag (AskFlag | None, optional) – If not None; does not ask the question and return the flag’s truth value.
- Returns:
- True if the user accepted / False if he didn’t.
True if the user’s input is unsupported and default_option is AskResult.YES False if the user’s input is unsupported and default_option is AskResult.NO True if flag is AskFlag.YES_TO_ALL False if flag is AskFlag.NO_TO_ALL default_option if flag is AskFlag.DEFAULT_TO_ALL
- Return type:
bool
Notes
If flag is not None, the question will not be displayed.
- Raises:
ValueError – If the default option ins’t AskResult.YES, or AskResult.NO.
ValueError – If the flag isn’t AskFlag.YES_TO_ALL, AskFlag.NO_TO_ALL, AskFlag.DEFAULT_TO_ALL, or None
ask_lib.ask_flag module#
- class ask_lib.ask_flag.AskFlag(value)#
Bases:
EnumEach member represent a flag that could be given by the user when the CLI was started.
Example:
import sys import ask_lib flag = ask_lib.AskFlag.YES_TO_ALL if "-Y" in sys.argv else None if ask_lib.ask("Delete file ?", flag=flag): print("Test")
- DEFAULT_TO_ALL = 'default_to_all'#
- NO_TO_ALL = 'no_to_all'#
- YES_TO_ALL = 'yes_to_all'#
ask_lib.ask_result module#
Module contents#
Utility function to ask for user’s confirmation in a CLI