I have a Python script that can deploy some software in three different environments, let's call them development
, testing
and production
. In order to select which environment the script should work with, I want to use mutually exclusive flags, like so:
./deploy.py --development
./deploy.py --testing
./deploy.py --production
So far I have this:
parser = argparse.ArgumentParser(description="Manage deployment")
group = parser.add_mutually_exclusive_group()
group.add_argument("-d", "--development", action='store_true', required=False)
group.add_argument("-t", "--testing", action='store_true', required=False)
group.add_argument("-p", "--production", action='store_true', required=False)
args = parser.parse_args()
Thing is, I want to have the environment in a single variable, so I can easily check it, instead of having to manually check args.development
, args.testing
and args.production
.
Is there a way of having a common variable that the three arguments could write to so I could do something like args.environment
?