Created
October 14, 2017 22:38
-
-
Save alzix/4868d66115a55567d3b43b32742f6f4f to your computer and use it in GitHub Desktop.
python argparse - deprecating options
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+class ActionStoreDeprecated(argparse.Action): | |
+ def __call__(self, parser, namespace, values, option_string=None): | |
+ logger.warn('DEPRECATED: using %s', '|'.join(self.option_strings)) | |
+ setattr(namespace, self.dest, values) | |
+ | |
+ | |
+class ActionAppendDeprecated(argparse.Action): | |
+ def __call__(self, parser, namespace, values, option_string=None): | |
+ logger.warn('DEPRECATED: using %s', '|'.join(self.option_strings)) | |
+ if not getattr(namespace, self.dest): | |
+ setattr(namespace, self.dest, []) | |
+ getattr(namespace, self.dest).append(values) | |
parser = argparse.ArgumentParser() | |
parser.add_argument( | |
'-f', | |
'--foo', | |
help='DEPRECATED: has no effect', | |
action=ActionStoreDeprecated | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment