Click实用工具函数
项目描述
为出色的Click库提供的实用工具函数(仅适用于Python 3)。Click是一个Python包,用于以尽可能少的代码以可组合的方式创建美观的命令行界面。
用法
from clickclick import Action, OutputFormat
with Action('Performing remote call..') as act:
do_something()
act.progress()
do_something_else()
output_format = 'json' # default: "text"
with OutputFormat(output_format):
print_table(['col1', 'col2'], rows)
工作示例
$ ./example.py
Usage: example.py [OPTIONS] COMMAND [ARGS]...
Options:
-V, --version Print the current version number and exit.
-h, --help Show this message and exit.
Commands:
list Example for Listings
localtime Print the localtime
output Example for all possible Echo Formats You see...
work-in-progress Work untile working is done
work_done Work done in ?? %
$ ./example.py l Usage: example.py [OPTIONS] COMMAND [ARGS]... Error: Too many matches: list, localtime
$ ./example.py lo Localtime: 2015-08-27 15:47:46.688547
$ ./example.py li Identifier|Name |Status |Creation Date|Description |Without Title 0 Column #0 ERROR -4228033s ago this is a verrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.. column without title 1 Column #1 FINE -4228033s ago this is a verrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.. column without title 2 Column #2 WARNING -4228033s ago this is a verrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.. column without title
$ ./example.py li -o tsv id name state creation_time desc without_title 0 Column #0 ERROR -4228033s ago this is a verrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrry long description column without title 1 Column #1 FINE -4228033s ago this is a verrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrry long description column without title 2 Column #2 WARNING -4228033s ago this is a verrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrry long description column without title
$ ./example.py li -o json [{"creation_time": 1444911300, "desc": "this is a verrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrry long description", "id": 0, "name": "Column #0", "state": "ERROR", "without_title": "column without title"}, {"creation_time": 1444911300, "desc": "this is a verrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrry long description", "id": 1, "name": "Column #1", "state": "FINE", "without_title": "column without title"}, {"creation_time": 1444911300, "desc": "this is a verrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrry long description", "id": 2, "name": "Column #2", "state": "WARNING", "without_title": "column without title"}]
$ ./example.py li -o yaml creation_time: 1444911300 desc: this is a verrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrry long description id: 0 name: 'Column #0' state: ERROR without_title: column without title --- creation_time: 1444911300 desc: this is a verrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrry long description id: 1 name: 'Column #1' state: FINE without_title: column without title --- creation_time: 1444911300 desc: this is a verrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrry long description id: 2 name: 'Column #2' state: WARNING without_title: column without title
$ ./example.py work- do anything.. OK create an excption.. EXCEPTION OCCURRED: No active exception to reraise Start with working.. . . . . OK Calc 1 + 1.. 2 Oh, I make an error.. work not complete done Oh, I make a warning.. work is complicated Start an exception.. EXCEPTION OCCURRED: name 'function_not_found' is not defined Make a final error.. this is the end..
$ ./example.py work_ 15.4 Please select the state of your work 1) Done 2) In Progress 3) unknown 4) lost Please select (1-4) [4]: 2 Your work is 15.4% In Progress
$ ./example.py work_ 15.4 Please select the state of your work 1) Done 2) In Progress 3) unknown 4) lost Please select (1-4) [4]: 3 Your work is 15.4% unknown
$ ./example.py work_ 15.4 Please select the state of your work 1) Done 2) In Progress 3) unknown 4) lost Please select (1-4) [4]: Your work is 15.4% lost
$ ./example.py output This is a ok: OK This is a ok with message:all is fine This is a warning: please check this Start with working.. . . . . OK Id|Name 1 Test #1 2 Test #2 Only FYI This is a error: this is wrong, please fix This is a fatal error: this is a fuckup
$ ./example.py output -o tsv id name 1 Test #1 2 Test #2
$ ./example.py output -o json [{"id": 1, "name": "Test #1"}, {"id": 2, "name": "Test #2"}]
$ ./example.py output -o yaml id: 1 name: 'Test #1' --- id: 2 name: 'Test #2'
许可证
版权(c)2015-2019 Zalando SE
根据Apache许可证版本2.0(“许可证”);除非您遵守许可证,否则不得使用此文件。您可以在以下位置获得许可证副本:
https://apache.ac.cn/licenses/LICENSE-2.0
除非适用法律要求或书面同意,否则在许可证下分发的软件按“原样”基础分发,不提供任何明示或暗示的保证或条件。有关许可证的具体语言,请参阅许可证。
项目详情
关闭
clickclick-20.10.2.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 4efb13e62353e34c5eef7ed6582c4920b418d7dedc86d819e22ee089ba01802c |
|
MD5 | 1d58cf500697561cb71a8dc164389b85 |
|
BLAKE2b-256 | c619f91d85941b79964d569a3729bf9f8b7f85ab47240248e77b7c0c8ed6ecc3 |
关闭
clickclick-20.10.2-py2.py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | c8f33e6d9ec83f68416dd2136a7950125bd256ec39ccc9a85c6e280a16be2bb5 |
|
MD5 | 8a807d01436cef03fbb5030a4d1c43e5 |
|
BLAKE2b-256 | 7a7ec08007d3fb2bbefb430437a3573373590abedc03566b785d7d6763b22480 |