也从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在Hibernate中从两个具有不同功能的表(postgreSQL)映射一个实体   java jfreechart需要自定义Y轴,以便打印   Java:从外部获取类。罐子   java如何获取Appium服务器日志   具有完全相同内容的java重写函数会导致错误   java消息的类路径是什么。属性(如果在依赖项jar中)   循环/相等的java问题==   java如何使用ionic cordova angularjs将所选图像发送到spring controller以保存到服务器?   库中的java语言环境数据   java从JSON webservice检索安卓中的字节[]   调试如何从Java中的类调试方法?   java将日期字符串切割成变量   无法使用java附加到文件?