Skip to content

Instantly share code, notes, and snippets.

@alzix
Created October 14, 2017 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alzix/4868d66115a55567d3b43b32742f6f4f to your computer and use it in GitHub Desktop.
Save alzix/4868d66115a55567d3b43b32742f6f4f to your computer and use it in GitHub Desktop.
python argparse - deprecating options
+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