点击实用功能

clickclick的Python项目详细描述


Travis CI build statushttps://coveralls.io/repos/zalando/python-clickclick/badge.svgPyPI DownloadsLatest PyPI versionLicense

实用程序函数(仅限python 3)用于美妙的Click library。 click是一个python包,用于以一种可组合的方式创建漂亮的命令行界面,所需的代码非常少。

用法

fromclickclickimportAction,OutputFormatwithAction('Performing remote call..')asact:do_something()act.progress()do_something_else()output_format='json'# default: "text"withOutputFormat(output_format):print_table(['col1','col2'],rows)

工作示例

看这个example scriptshell script

$./example.pyUsage:example.py[OPTIONS]COMMAND[ARGS]...Options:-V,--versionPrintthecurrentversionnumberandexit.-h,--helpShowthismessageandexit.Commands:listExampleforListingslocaltimePrintthelocaltimeoutputExampleforallpossibleEchoFormatsYousee...work-in-progressWorkuntileworkingisdonework_doneWorkdonein??%
$ ./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 Zalando SE

根据apache许可证2.0版(以下简称“许可证”)授权; 除非符合许可证,否则您不能使用此文件。 您可以在

http://www.apache.org/licenses/LICENSE-2.0

除非适用法律要求或书面同意,否则软件 根据许可证分发是按“原样”分发的, 无任何明示或默示的保证或条件。 有关管理权限的特定语言和 许可下的限制。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
for循环如何使用Java8流迭代x次?   macos如何从java代码执行以下命令行表达式?   java为什么可以使用类名作为向量类型?   在Java中读取平面文件中的XML文件   java为什么gradlew在不同的机器上构建不同的JAR?   线程“main”java中出现异常。lang.NoClassDefFoundError:名称错误:   java安装了Eclipse2006,但没有在文件>新建部分下获取Maven项目   用Java绘制头部和颈部。拉绳问题   线程“main”java中出现异常。lang.ArrayIndexOutofBounds异常:65   java为什么用通配符创建的比较器的compare方法不能接受对象?   date查找Java未来十年特定节日的一周中的哪一天   哈希匹配Java SHA2输出与MySQL SHA2输出   java JsArray从html5存储接收数据后无法返回长度   当实例的成员暴露于外部世界时,可以对其进行垃圾收集   java eclipse允许一次只查看一个表达式吗