I have set up a script with argparse that gives me the following NameSpace:
Namespace(action='list', input='all', target='domain')
I have made a few functions which are called according to the positionals, and at the moment I have a working situation by calling them with blurbs of code like this one:
if args.action == 'list':
if len(sys.argv) == 2:
parser.print_help()
sys.exit(0)
elif args.target == 'domain':
domain_list()
elif args.target == 'forwarding':
forwarding_list()
elif args.target == 'transport':
transport_list()
elif args.target == 'user':
user_list()
else:
all_list()
I know this can be done way, way better than this; but with my limited knowledge of Python, I can't seem to figure this one out.
Recap: I want something like, if at all possible (pseudocode)
if args.action == 'add':
target = args.target
target_add()
where target_add()
is something like domain_add()
.
Thanks in advance!