从CLI执行Python可调用对象!
项目描述
clitoo: 从CLI执行Python可调用对象!
有时候我想在命令行上执行一个带有一些参数的Python回调,但我总是很沮丧,因为它总是需要将我的命令包装在一些包装器中,或者做更多的事情,只是从CLI调用一个参数化的回调。
Clitoo让我不再沮丧。
安装
$ pip install clitoo
帮助
Clitoo makes your python callbacks work on CLI too ! This CLI can execute python callbacks with parameters. Clitoo recognizes 4 types of command line arguments: - lone arguments are passed as args - arguments with = are passed as kwargs - dashed arguments like -f arrive in context.args - dashed arguments like -foo=bar arrive in context.kwargs It doesn't matter how many dashes you put in the front, they are all removed. To use the context in your callback just import the clitoo context:: from clitoo import context print(context.args, context.kwargs) Clitoo provides 2 builtin commands: help and debug. Any other first argument will be considered as the dotted path to the callback to import and execute. Examples: clitoo help your.mod.funcname Print out the function docstring. clitoo debug your.func -a --b --something='to see' how it=parses Dry run of your.mod with arguments, dump out actual calls. clitoo your.mod.funcname with your=args Call your.mod.funcname('with', your='args').
演示
$ clitoo debug your.func -a --b --something='to see' how it=parses Could not import your.func nor clitoo.your.func Args: ('how',) Kwargs: {'it': 'parses'} Context args: ['a', 'b'] Context kwargs: {'something': 'to see'}
回退
Clitoo会尝试回退到它自己的包。如果它找不到来自git包的git.clone回调,或者找不到git包本身,它会找到clitoo.git.clone,这是一个我们在CI中使用的内置命令。
创建自己的命令
查看djcli存储库中包装为独立命令的示例,但它看起来像
# Declare the following as CLI entry_point def cli(): clitoo.context.default_module = __name__ return clitoo.main()
项目详情
关闭
clitoo-1.0.2.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 463cd4097798ce4f7bff13b7ac9eeb83d8fcfdda49a97437eba369377bef9ee9 |
|
MD5 | 24c97b00bdaa21fc1ff45df136948a7d |
|
BLAKE2b-256 | 04effdbafd0989af5c15c8cc2a063c0e96feea8186e02f21d67320825964c46b |