Python Argparse Flags依赖于Task

时间:2017-10-22 03:27:58

标签: python python-3.x argparse

所以我有一个程序,我在python 3.5中使用argparse编写。现在我遇到了一个问题,我想在那里为任务指定标志。

wasp init -m

wasp tag -g

但我希望-g不适用于init,反之亦然 我目前只有init功能正常工作,但我不想添加-g标志,直到我知道如何处理tag

来源在这里:

description = 'Generate and create basic resources for a modern web app. Initialize a project with a manifest, package, and tags versions effectively'
parser = argparse.ArgumentParser(description=description)
parser.add_argument('task', metavar='task', type=str, help='A task to perform. Options : init, update, tag')
parser.add_argument('-m', '--manifest', action='store_true', help='Generate a manifest.json for your project')
parser.add_argument('-p', '--package', action='store_true', help='Generate a package.json for your project')

0 个答案:

没有答案