prompt_smart_menu package¶
Submodules¶
prompt_smart_menu.helpers module¶
Shared helper classes.
-
exception
prompt_smart_menu.helpers.InvalidArgError(ex: Exception)[source]¶ Bases:
ExceptionInvalid argument. Wrapper around various built-in exceptions.
prompt_smart_menu.input_parser module¶
Parse a command string into arguments.
-
class
prompt_smart_menu.input_parser.InputParser(*args)[source]¶ Bases:
objectFor parsing a command string into desired types or objects.
-
parse(input_string: str, recurse: bool = False) → list[source]¶ Parse an argument from a command string.
Parameters: - input_string (str) – command string to be prased
- recurse (bool) – If true, the entire input_string is parsed. Otherwise, only the first argument is parsed. Default: False
Returns: - A list of parsed commands. If recurse=False, the list has
two items. The first is the parsed argument, the second is the remaining command string.
Return type: list
-
-
class
prompt_smart_menu.input_parser.KwargCast[source]¶ Bases:
objectCast a string to be used as a keyword argument.
String must match the following regex: r’–(w+)=(.*)’ The key must also be a valid python identifier.
-
identifier_re= re.compile('^[^\\d\\W]\\w*\\Z')¶
-
kwarg_re= re.compile('--(\\w+)=(.*)')¶
-
prompt_smart_menu.smart_menu module¶
Build a command line menu declaratively.
-
class
prompt_smart_menu.smart_menu.MenuNode(*, command: str, function: Callable = None, children: Union[List[dict], List[str], prompt_smart_menu.helpers.NestedDict] = None, parser: prompt_smart_menu.input_parser.InputParser = <prompt_smart_menu.input_parser.InputParser object>, validate_args: bool = False)[source]¶ Bases:
objectThe MenuNode class for PromptSmartMenu sub/commands.
Don’t use this class directly. Initialize with PromptSmartMenu.
-
process_arg(args_str: str)[source]¶ Parse an argument from a command string and process appropriately.
If this MenuNode has a function, the entire command string is parsed and sent to the function as arguments. Otherwise, a single argument is parsed and the remaining command string is sent to the appropriate child MenuNode, if it exists.
Parameters: args_str (str) – The command string to be parsed and processed. Raises: InvalidArgError– Raised in a few situations. If this MenuNode is not an end-point but was given no commands. If not an end-point and given a non-existent subcommand. If validate_args=True and arguments are invalid.
-
-
class
prompt_smart_menu.smart_menu.PromptSmartMenu(menu_config: List[dict], parser: prompt_smart_menu.input_parser.InputParser = <prompt_smart_menu.input_parser.InputParser object>, validate_args: bool = False)[source]¶ Bases:
objectThe main PromptSmartMenu class.
Declare a menu’s configuration as list of menu_node dicts. Initialize a PromptSmartMenu object with this configuration to generate a dict for auto-suggestion and to execute a command string against your menu.
-
prompt_smart_menu.smart_menu.is_list_of_dicts(li: list) → bool[source]¶ Return true if input is a list of dicts.
Module contents¶
prompt_smart_menu¶
- Description: prompt_smart_menu is a library for building command line menus for
- terminal applications in Python. It allows you to create a multi-tiered argument parsing menu for executing different subcommands of a command line application.
See documentation for usage.
-
class
prompt_smart_menu.NestedDict(nest: dict)[source]¶ Bases:
objectA wrapper around a nested dict.
- Dict should be of the format that can be given to prompt_toolkit function:
- NestedCompleter.from_nested_dict(dict)
-
nest¶ Nest property.
-
class
prompt_smart_menu.PromptSmartMenu(menu_config: List[dict], parser: prompt_smart_menu.input_parser.InputParser = <prompt_smart_menu.input_parser.InputParser object>, validate_args: bool = False)[source]¶ Bases:
objectThe main PromptSmartMenu class.
Declare a menu’s configuration as list of menu_node dicts. Initialize a PromptSmartMenu object with this configuration to generate a dict for auto-suggestion and to execute a command string against your menu.