[英]Azure - Python - parse arguments from command line
社區,
我正在嘗試使用Python CLI將參數解析為Azure主體憑據的默認值。 在我的代碼中,我嘗試將“ --azure-client-id”,“-azure-secret”,“-azure-tenant”和“ --azure-subscription-id”的默認值硬編碼為默認值,但我不是100%如何添加它。 我一直在網上搜索,但仍找不到答案
我仍在學習,希望有人能幫助我。
預先感謝您的幫助
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',默認='ID')
NARGS = '?' = 0或1個參數
const ='ID'=設置不傳遞任何參數時的默認值
default ='ID'=如果未指定'--azure-client-id',則為默認值
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.