shell calls sys.__interativehook__

This will set up readline tab and history completion by default.
This commit is contained in:
David Lord 2021-04-14 10:01:32 -07:00
parent 64213fc021
commit 32272da9ac
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
2 changed files with 20 additions and 0 deletions

View file

@ -887,6 +887,24 @@ def shell_command():
ctx.update(app.make_shell_context())
# Site, customize, or startup script can set a hook to call when
# entering interactive mode. The default one sets up readline with
# tab and history completion.
interactive_hook = getattr(sys, "__interactivehook__", None)
if interactive_hook is not None:
try:
import readline
from rlcompleter import Completer
except ImportError:
pass
else:
# rlcompleter uses __main__.__dict__ by default, which is
# flask.__main__. Use the shell context instead.
readline.set_completer(Completer(ctx).complete)
interactive_hook()
code.interact(banner=banner, local=ctx)