Skip to content

Instantly share code, notes, and snippets.

@buanzo
Last active May 6, 2020 14:35
Show Gist options
  • Save buanzo/2a004348340ef79b0139ab38f719cf1e to your computer and use it in GitHub Desktop.
Save buanzo/2a004348340ef79b0139ab38f719cf1e to your computer and use it in GitHub Desktop.
Python 3 Argparse.Action to use on not-implemented arguments
#!/usr/bin/env python3
import sys
import argparse
""" This class allows to work on getting your Argparse object
ready even if nothing useful happens when used.
Save this git on some file then import the class.
Usage:
Just set action=NotImplementedAction when calling add_argument, like this:
import argparse
from notimplemented import NotImplementedAction
parser = argparse.ArgumentParser()
parser.add_argument("--missing",
help="This will do something in the future",
action=NotImplementedAction)
"""
class NotImplementedAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
msg = 'Argument "{}" still not implemented.'.format(option_string)
sys.exit(msg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment