diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2018-06-27 06:23:24 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-27 06:23:24 -0700 |
commit | 4d91bf066f2e285f53b3228a92f23053a94ec4fa (patch) | |
tree | d2d036428b66d9257ac13de28a302917d711a439 | |
parent | 428e6d9817612c0de91a148361c34a91a15479cf (diff) | |
parent | ff2a73219896b945b84e2320260e452cf351bceb (diff) | |
download | cmd2-git-4d91bf066f2e285f53b3228a92f23053a94ec4fa.tar.gz |
Merge branch 'master' into table_display
-rwxr-xr-x | cmd2/argparse_completer.py | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/cmd2/argparse_completer.py b/cmd2/argparse_completer.py index 995aeb48..60af25de 100755 --- a/cmd2/argparse_completer.py +++ b/cmd2/argparse_completer.py @@ -81,6 +81,33 @@ ACTION_DESCRIPTIVE_COMPLETION_HEADER = 'desc_header' class CompletionItem(str): + """ + Completion item with descriptive text attached + + Returning this instead of a regular string for completion results will signal the + autocompleter to output the completions results in a table of completion tokens + with descriptions instead of just a table of tokens. + + For example, you'd see this: + TOKEN Description + MY_TOKEN Info about my token + SOME_TOKEN Info about some token + YET_ANOTHER Yet more info + + Instead of this: + TOKEN_ID SOME_TOKEN YET_ANOTHER + + This is especially useful if you want to complete ID numbers in a more + user-friendly manner. For example, you can provide this: + + ITEM_ID Item Name + 1 My item + 2 Another item + 3 Yet another item + + Instead of this: + 1 2 3 + """ def __new__(cls, o, desc='', *args, **kwargs) -> str: return str.__new__(cls, o, *args, **kwargs) @@ -1196,9 +1223,9 @@ class ACArgumentParser(argparse.ArgumentParser): # twice (which may fail) if the argument was given, but # only if it was defined already in the namespace if (action.default is not None and - isinstance(action.default, str) and - hasattr(namespace, action.dest) and - action.default is getattr(namespace, action.dest)): + isinstance(action.default, str) and + hasattr(namespace, action.dest) and + action.default is getattr(namespace, action.dest)): setattr(namespace, action.dest, self._get_value(action, action.default)) |