我试图创建一个带有层次命令的命令行应用程序(我的子命令将有子命令)。但是,当我尝试一个非常基本的应用程序时,我得到一个AttributeError
。在
我可以用一个简单的例子来复制这一点。在
.
├── cli.py
└── commands
├── config_cmds.py
├── __init__.py
import click
@click.group
@click.version_option()
def configcmd():
"""Configuration management for this CLI"""
click.echo("In config")
如果运行此应用程序,则会出现以下错误:
$ python cli.py
Traceback (most recent call last):
File "cli.py", line 15, in <module>
cli.add_command(configcmd)
File "/home/frank/.virtualenvs/clitest/lib/python3.6/site-packages/click/core.py", line 1221, in add_command
name = name or cmd.name
AttributeError: 'function' object has no attribute 'name'
我的目录结构是基于this答案设置的。在
我使用的是python3.6并单击version7.0。在
如何解决此属性错误,以便可以有一个命令层次结构并将命令拆分为多个文件?在
您需要调用
click.group()
修饰符,如下所示:测试代码:
^{pr2}$结果:
相关问题 更多 >
编程相关推荐