summaryrefslogtreecommitdiff
path: root/email-print-mime-structure
diff options
context:
space:
mode:
authorDaniel Kahn Gillmor <dkg@fifthhorseman.net>2019-11-10 09:31:58 -0500
committerSean Whitton <spwhitton@spwhitton.name>2019-11-10 09:00:15 -0700
commit818dba1efe67f7b01f6d601c6462a40567c9ed7f (patch)
tree2f194e6d58278545f264adf9f2a70867b9562f56 /email-print-mime-structure
parent677d6ed933a073a3bc3b2c461f49a97b0cbefebd (diff)
downloadmailscripts-818dba1efe67f7b01f6d601c6462a40567c9ed7f.tar.gz
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 <dkg@fifthhorseman.net>
Diffstat (limited to 'email-print-mime-structure')
-rwxr-xr-xemail-print-mime-structure15
1 files changed, 15 insertions, 0 deletions
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)