Skip to content

Instantly share code, notes, and snippets.

@eegilbert
Forked from frenchtoast747/flag_per_function.py
Created June 26, 2018 11:20
Show Gist options
  • Save eegilbert/662a08cf11b64ba5b591359806b1c2ef to your computer and use it in GitHub Desktop.
Save eegilbert/662a08cf11b64ba5b591359806b1c2ef to your computer and use it in GitHub Desktop.
Flag per function - Argparse
import argparse
class c1(object):
def cleanup(self):
print 'c1'
class c2(object):
def cleanup(self):
print 'c2'
class c3(object):
def cleanup(self):
print 'c3'
parser = argparse.ArgumentParser()
parser.add_argument('-1', const=c1, dest='cleaners', action='append_const')
parser.add_argument('-2', const=c2, dest='cleaners', action='append_const')
parser.add_argument('-3', const=c3, dest='cleaners', action='append_const')
args = parser.parse_args()
if args.cleaners is not None:
for cleaner_class in args.cleaners:
cleaner = cleaner_class()
cleaner.cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment