add add_deprecated_argument

This commit is contained in:
Brad Warren
2015-11-30 17:56:42 -08:00
parent 224eb1cd1a
commit c72e122943
+21
View File
@@ -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)