也从cli执行python可调用函数!

clitoo的Python项目详细描述


cli too:也从cli执行python可调用函数!

有时我想在命令上执行带有一些参数的python回调 行,但我很沮丧它总是需要把我的命令包装成 某种类型的包装器,或者做一些比调用参数化 从cli回调。

克莱托不信任我。

安装:

$ 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.clonegit包回调,或找不到git包 它本身会找到clitoo.git.clone,这是我们使用的内置命令 在ci中。

制定自己的命令

有关打包为 独立的,但看起来像:

# Declare the following as CLI entry_point
def cli():
    clitoo.context.default_module = __name__
    return clitoo.main()

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

推荐PyPI第三方库


热门话题
java类。getConstructor找不到兼容的构造函数   java单元测试自定义输入和输出格式   javascript Java UI线程内存不足错误被阻止   多线程在Java并发API中从线程池中选择线程的逻辑是什么?   java在MySQL数据库上存储歌曲(BLOb支持)   java快速且可扩展的IO传递   jsf c:forEach-inside-primeface(例如p:panelgrid)inside-ui:repeat   tomcat与JavaServlet3.0文件上传,如何获取maxfilesize值   java JNI,加载2次相同的dll(不同的名称),如何选择使用哪一个?   java将InputStream复制到OutputStream将停止,除非我也向系统写入。出来   java Set反向安全约束   比如在java中使用整数时?   java使用@接口抑制IntelliJ中的某些警告   java我的ASCII艺术在JLabel上是错误的   JavaSpring工具源代码(或带有SpringIde的Eclipse)崩溃   向片段添加ListView时出现java错误   循环Java循环错误需要重新审视   JavaAspectJ:匹配GenericServlet。带注释子类实例的init()调用