将帮助参数添加到@app.cli.command()

adding help parameter to @app.cli.command()

所以我得到了以下点击命令

from flask import Flask

app = Flask(__name__)

@app.cli.command()
def hello():
    print("hello from inside flask")

然后尝试向其中添加一个 'help',如下所示:

@app.cli.command()
@app.cli.argument(help='test command to say hello from inside flask')
def hello():
    print("hello from inside flask")

..但是它说

AttributeError: 'AppGroup' object has no attribute 'argument'

如果你有

,我相信这应该有效
import click
@click.option(help="use this command like this")

@click.argument(help="use this command like this")

如果你有@app.cli.command(),有人知道如何让它工作吗?

Click 不支持将 help 参数传递给 click.argument,仅支持传递给 click.option。这在文档的几个地方被引用:

https://click.palletsprojects.com/en/7.x/documentation/#help-texts

Arguments cannot be documented this way. This is to follow the general convention of Unix tools of using arguments for only the most necessary things and to document them in the introduction text by referring to them by name.

https://click.palletsprojects.com/en/7.x/parameters/#differences

options are fully documented in the help page, arguments are not (this is intentional as arguments might be too specific to be automatically documented)

https://click.palletsprojects.com/en/7.x/arguments/

Click will also not attempt to document arguments for you and wants you to document them manually in order to avoid ugly help pages.

相反,Click 希望您直接在命令的文档字符串中记录参数。这是因为参数通常与命令帮助文本更紧密地结合在一起,所以 Click 不会尝试自己编写。

import click

@click.command()
@click.argument("name")
def hello(name):
    """Say hello to NAME."""
    click.echo(f"Hello, {name}!")

您可以在 Click 的问题跟踪器上找到讨论和一些添加参数帮助的示例:https://github.com/pallets/click/pull/1051。不过,目前没有计划更改 Click 处理此问题的方式。