I am writing an interactive command line Python program. The command lines that the user enters are auto-completed with Python Prompt Toolkit, and are parsed with argparse. There are multiple commands, each one with different syntax and completions. To do this, I have a nested completer at the top level that is built by different “handler” classes.
I would like to implement a command in the following format
cmd name [--params [key1=value12] [key2=value21] ...]
Depending on the value of “name”, the user may specify additional parameters in the form of key=value, and the number of parameters is variable. In theory, I should be able to do this with NestedCompleter, with a dictionary like this:
{'key1': {
'value11': None,
'value12': None},
'key2': {
'value21':None,
'value22':None}
}
I would then be able to add this dict to the top level NestedCompleter.
The problem is that the above NestedCompleter would separate the keys and values with a space and would not work if I want to separate them with an ‘=’. I’m not sure how to implement a NestedCompleter that can treat the ‘=’ like a space. Is there any way of doing that?