summaryrefslogtreecommitdiff
path: root/cmd2/argcomplete_bridge.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2018-06-09 19:01:41 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2018-06-09 19:01:41 -0400
commit6c2b3193b1d99aaa183fdde8f9bcf5288522d854 (patch)
tree03aa4111e86508b2172192483dd1b193f938f73a /cmd2/argcomplete_bridge.py
parent19a1f764119aa1c4e391c06b18c0f101ef20a7ce (diff)
downloadcmd2-git-6c2b3193b1d99aaa183fdde8f9bcf5288522d854.tar.gz
Added back bash_complete() helper function to argcomplete_bridge.py
This is intended to be used once a new example is added to show how to use the code present in argcomplete_bridge. This was previously used by the subcommands.py example, but I deleted the argcomplete_bridge code from there to simplify that example and make it focused on subcommands.
Diffstat (limited to 'cmd2/argcomplete_bridge.py')
-rw-r--r--cmd2/argcomplete_bridge.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/cmd2/argcomplete_bridge.py b/cmd2/argcomplete_bridge.py
index ee52a466..7bdb816f 100644
--- a/cmd2/argcomplete_bridge.py
+++ b/cmd2/argcomplete_bridge.py
@@ -16,6 +16,7 @@ else:
except AttributeError:
DEFAULT_COMPLETER = argcomplete.completers.FilesCompleter()
+ from cmd2.argparse_completer import ACTION_ARG_CHOICES, ACTION_SUPPRESS_HINT
from contextlib import redirect_stdout
import copy
from io import StringIO
@@ -250,3 +251,15 @@ else:
output_stream.flush()
argcomplete.debug_stream.flush()
exit_method(0)
+
+
+ def bash_complete(action, show_hint: bool = True):
+ """Helper function to configure an argparse action to fall back to bash completion.
+
+ This function tags a parameter for bash completion, bypassing the autocompleter (for file input).
+ """
+ def complete_none(*args, **kwargs):
+ return None
+
+ setattr(action, ACTION_SUPPRESS_HINT, not show_hint)
+ setattr(action, ACTION_ARG_CHOICES, (complete_none,))