Skip to content

Commit 6c2b319

Browse files
committed
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.
1 parent 19a1f76 commit 6c2b319

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

cmd2/argcomplete_bridge.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
except AttributeError:
1717
DEFAULT_COMPLETER = argcomplete.completers.FilesCompleter()
1818

19+
from cmd2.argparse_completer import ACTION_ARG_CHOICES, ACTION_SUPPRESS_HINT
1920
from contextlib import redirect_stdout
2021
import copy
2122
from io import StringIO
@@ -250,3 +251,15 @@ def __call__(self, argument_parser, completer=None, always_complete_options=True
250251
output_stream.flush()
251252
argcomplete.debug_stream.flush()
252253
exit_method(0)
254+
255+
256+
def bash_complete(action, show_hint: bool = True):
257+
"""Helper function to configure an argparse action to fall back to bash completion.
258+
259+
This function tags a parameter for bash completion, bypassing the autocompleter (for file input).
260+
"""
261+
def complete_none(*args, **kwargs):
262+
return None
263+
264+
setattr(action, ACTION_SUPPRESS_HINT, not show_hint)
265+
setattr(action, ACTION_ARG_CHOICES, (complete_none,))

0 commit comments

Comments
 (0)