diff --git a/letsencrypt/le_util.py b/letsencrypt/le_util.py index 25260d755..3d124e2f8 100644 --- a/letsencrypt/le_util.py +++ b/letsencrypt/le_util.py @@ -1,4 +1,5 @@ """Utilities for all Let's Encrypt.""" +import argparse import collections import errno import logging @@ -255,3 +256,23 @@ def safe_email(email): else: logger.warn("Invalid email address: %s.", email) return False + + +def add_deprecated_argument(add_argument, argument_name): + """Adds a deprecated argument with the name argument_name. + + Deprecated arguments are not shown in the help. If they are used on + the command line, a warning is shown stating that the argument is + deprecated and no other action is taken. + + :param callable add_argument: Function that adds arguments to an + argument parser/group. + :param str argument_name: Name of deprecated argument. + + """ + class ShowWarning(argparse.Action): + """Action to log a warning when an argument is used.""" + def __call__(self, unused1, unused2, unused3, option_string=None): + print "Use of {0} is deprecated".format(option_string) + + add_argument(argument_name, action=ShowWarning, help=argparse.SUPPRESS)