【发布时间】:2018-06-12 15:50:00
【问题描述】:
我将写一些非常基本的东西来解释我想要实现的目标。我写了一些代码来做一些有趣的 WordPress 管理。该程序将创建实例,但也会为 apache 创建 https 设置。
我希望它做什么以及我遇到问题的地方: (如果您在 wp cli 上运行帮助,您将确切地看到我想要发生的事情......但我不是开发人员,所以我需要一些帮助)
python3 testcommands.py --help
Usage: testcommands.py [OPTIONS] COMMAND [ARGS]...
This is the help
Options:
--help Show this message and exit.
Commands:
https Commands for HTTPS
wp Commands for WP
python3 testcommands.py https --help
Usage: testcommands.py [OPTIONS] COMMAND [ARGS]...
This is the help
Options:
--help Show this message and exit.
Commands:
create Creates config for HTTPS
sync Syncs config for Apache
我的基本代码:
import click
@click.group()
def cli1():
pass
"""First Command"""
@cli1.command('wp')
def cmd1():
"""Commands for WP"""
pass
@cli1.command('install')
@click.option("--test", help="This is the test option")
def install():
"""Test Install for WP"""
print('Installing...')
@click.group()
def cli2():
pass
"""Second Command"""
@cli2.command('https')
def cmd2():
click.echo('Test 2 called')
wp = click.CommandCollection(sources=[cli1, cli2], help="This is the help")
if __name__ == '__main__':
wp()
返回:
python3 testcommands.py --help
Usage: testcommands.py [OPTIONS] COMMAND [ARGS]...
This is the help
Options:
--help Show this message and exit.
Commands:
https
install Test Install for WP
wp Commands for WP
我想不通。我不想 install 在这里显示,因为它应该在 wp 下方以免显示。
谢谢你能帮我...我相信这很简单...或者不可能...但无论如何谢谢。
【问题讨论】:
标签: python python-3.x command-line-interface python-click