简体   繁体   中英

Azure - Python - parse arguments from command line

community,

I am trying to parse arguments as default values for principal credentials on Azure using Python CLI. In my code, I am trying to hardcode the default values for the " --azure-client-id", "--azure-secret", "--azure-tenant" and "--azure-subscription-id" as default but I am not 100% how to add it. I have been searching all over the net but can't find the answer as yet

I am still learning and I was hoping that someone could help me.

Thank you in advances for your help

My code below

def parse_args(args): '''parse arguments from command line''' variables = {} parser = argparse.ArgumentParser() parser.add_argument("action", help="the command to be action", choices=["delete", "create"], nargs='?', default="set") parser.add_argument("-f", "--folder", dest="folder", nargs='?', help="folder container ARM template & parameters json", metavar="FOLDER") parser.add_argument("-b", "--build-number", dest="build_number", help="build number of the resource number") parser.add_argument("-c", "--azure-client-id", dest="azure_client_id", help="azure client id") parser.add_argument("-s", "--azure-secret", dest="azure_secret", help="azure secret") parser.add_argument("-t", "--azure-tenant", dest="azure_tenant", help="azure tenant") parser.add_argument("-sid", "--azure-subscription-id", dest="azure_subscription_id", help="azure subscription id") args = parser.parse_args(args)

parser.add_argument('--azure-client-id', nargs='?', const='ID', default='ID')

nargs='?' = 0 or 1 arguments

const='ID' = sets default value when no arguments are passed

default='ID' = if '--azure-client-id' is not specified this will be the default value

https://docs.python.org/3/library/argparse.html#nargs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM