From 818dba1efe67f7b01f6d601c6462a40567c9ed7f Mon Sep 17 00:00:00 2001 From: Daniel Kahn Gillmor Date: Sun, 10 Nov 2019 09:31:58 -0500 Subject: email-print-mime-structure: add tab completion This is modeled after the use of argcomplete in diffoscope, and it should be possible to use it for any other pythonic mailscript that uses argparse. Signed-off-by: Daniel Kahn Gillmor --- email-print-mime-structure | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'email-print-mime-structure') diff --git a/email-print-mime-structure b/email-print-mime-structure index 5497597..aac8194 100755 --- a/email-print-mime-structure +++ b/email-print-mime-structure @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +# PYTHON_ARGCOMPLETE_OK # -*- coding: utf-8 -*- # Copyright (C) 2019 Daniel Kahn Gillmor @@ -45,6 +46,11 @@ try: except ImportError: pgpy = None +try: + import argcomplete #type: ignore +except ImportError: + argcomplete = None + class MimePrinter(object): def __init__(self, args:Namespace): self.args = args @@ -152,6 +158,15 @@ def main() -> None: parser.add_argument('--use-gpg-agent', metavar='true|false', type=bool, default=False, help='Ask local GnuPG installation for decryption') + + if argcomplete: + argcomplete.autocomplete(parser) + elif '_ARGCOMPLETE' in os.environ: + logging.error('Argument completion requested but the "argcomplete" ' + 'module is not installed. ' + 'Maybe you want to "apt install python3-argcomplete"') + sys.exit(1) + args:Namespace = parser.parse_args() msg:Union[Message, str, int, Any] = email.message_from_file(sys.stdin) -- cgit v1.2.3