So I’m trying to parse the command line for 2 groups of mutually exclusive arguments.
- The user can specify a file
- The user can specify a server
along with a view
I’m looking at the argparse.add_mutually_exclusive_group function. However, it doesn’t seem like it will do what I need. I want to let someone specify a file or specify a jenkins server with a view. I don’t know how to manipulate add_mutually_exclusive_group to either accept a 1 argument group or a 2 argument group. I will save everyone the pain of looking at my other failed trials but I’m getting the feeling either
- I’m using add_mutually_exclusive_group wrong or
- I’m using the wrong function to accomplish what I want.
Here’s my code, although, I know it’s wrong because I’m not using it correctly to make jenkins and view be a group but I don’t know what to do to accomplish that.
parser = argparse.ArgumentParser()
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('--file', dest='file', help='Get jobs from file')
group.add_argument('--jenkins', dest='jenkins', help='Get jobs from Jenkins view and separate by section')
group.add_argument('--view', dest='view')