我有一个烧瓶应用程序,在它的一个脚本命令中我想知道传递给管理器的参数是什么(而不是命令本身),我该怎么做?
$ cat manage.py
#!/usr/bin/env python
from flask import Flask
from flask_script import Manager
app = Flask(__name__)
manager = Manager(app)
manager.add_option("-d", "--debug", dest="debug", action="store_true")
@manager.option('-n', '--name', dest='name', default='joe')
def hello(name):
# how can I know whether "-d|--debug" is passed in command line
print("hello", name)
if __name__ == "__main__":
manager.run()
如果我运行:
$ python manage.py --debug hello
我想检测是否'--debug'
通过 .func 的命令行参数传递hello
。我不能只是改变
manager.add_option("-d", "--debug", dest="debug", action="store_true")
到装饰器版本:
@manager.option('-d', '--debug', action='store_true', dest='debug')
@manager.option('-n', '--name', dest='name', default='joe')
def hello(name, debug=False):
因为'-d|--debug'
被许多命令共享。