AsyncClick中缺少选项组
项目描述
click-option-group
click-option-group是一个Click扩展包,它添加了Click中缺少的选项组功能。
目标和动机
Click是一个用于在Python中创建强大而美观的命令行界面(CLI)的包,但它没有创建选项组的函数。
选项组是一种方便的机制,用于逻辑组织CLI,同时也允许您设置分组选项的特定行为和关系(例如互斥选项)。此外,argparse标准库包包含此功能。
同时,许多Click用户需要此功能。您可以在以下问题中阅读有关此功能的有趣讨论
本包的目的是提供具有可扩展功能的组选项,使用规范且干净的API(尽可能使用类似Click的API)。
快速入门
安装
使用pip安装和更新
pip install -U click-option-group
简单示例
这是一个简单示例,说明如何在基于Click的CLI中使用选项组。只需使用optgroup
通过装饰类似Click API的命令函数来声明选项组。
# app.py
import click
from click_option_group import optgroup, RequiredMutuallyExclusiveOptionGroup
@click.command()
@optgroup.group('Server configuration',
help='The configuration of some server connection')
@optgroup.option('-h', '--host', default='localhost', help='Server host name')
@optgroup.option('-p', '--port', type=int, default=8888, help='Server port')
@optgroup.option('-n', '--attempts', type=int, default=3, help='The number of connection attempts')
@optgroup.option('-t', '--timeout', type=int, default=30, help='The server response timeout')
@optgroup.group('Input data sources', cls=RequiredMutuallyExclusiveOptionGroup,
help='The sources of the input data')
@optgroup.option('--tsv-file', type=click.File(), help='CSV/TSV input data file')
@optgroup.option('--json-file', type=click.File(), help='JSON input data file')
@click.option('--debug/--no-debug', default=False, help='Debug flag')
def cli(**params):
print(params)
if __name__ == '__main__':
cli()
$ python app.py --help
Usage: app.py [OPTIONS]
Options:
Server configuration: The configuration of some server connection
-h, --host TEXT Server host name
-p, --port INTEGER Server port
-n, --attempts INTEGER The number of connection attempts
-t, --timeout INTEGER The server response timeout
Input data sources: [mutually_exclusive, required]
The sources of the input data
--tsv-file FILENAME CSV/TSV input data file
--json-file FILENAME JSON input data file
--debug / --no-debug Debug flag
--help Show this message and exit.
文档
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源代码分发
asyncclick_option_group-0.5.6.1.tar.gz (22.6 kB 查看哈希值)
构建分发
关闭
asyncclick_option_group-0.5.6.1.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 5f63d8ea4ed95f87a6060905a7a7cf8aaf2f4ac2a9173794686122f0c8a5445e |
|
MD5 | 6dea857f0f053d1936e17f6d6294a97b |
|
BLAKE2b-256 | 7d2d3eb399edf0b78d39aebbc01c22a368a5399c3b2dd55db43d131e0de858d1 |
关闭
asyncclick_option_group-0.5.6.1-py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 3ecc68b659189cae569a13e7ae248c509aeb1b0acef6fa093f48b8a068850f18 |
|
MD5 | c63f8c850dcd9d53eaa905757a0cec2f |
|
BLAKE2b-256 | cc082e943e390e6a2f35fe7ed3acbd85ae4bef48e14a6c308e2329f1b9ce4e5a |