The way I would implement this is:
import argparse
def printLogs():
print("logs!")
parser = argparse.ArgumentParser()
parser.add_argument('-e','--entry', type=str, help='New entry')
parser.add_argument("-l", action="store_true", help='print logs')
args = parser.parse_args()
if args.l:
printLogs()
The primary purpose of argparse
is to parse the input (sys.argv
), and give you a set of argument values (args
is a simple namespace
object). callbacks
is a optparse
concept that have not been included in argparse
.
The FooAction
example in the docs, http://docs.python.org/3.4/library/argparse.html#action, does something like this optparse
callback. It prints some information when called, and then does the important thing - set a value in the namespace.