也从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对ServiceListener和ServiceTracker调用提供了哪些排序保证?   java找不到方法格式的符号(DateTimeFormatter)?   mysql有没有一种方法可以将TCPDump输出到一个文件中,并用Java对其进行过滤,每5秒钟用新数据覆盖一次该文件?   java如何最好地配置用户上传支持文件的上传位置   java我在Android上使用OData4j,我无法获取实体   JPA实体关系简单示例中的java获取错误   JAVANoClassDefFoundError:安卓。应用程序。用法安卓中的UsageStatsManager   Eclipse中javaoo代码分析   java MethodVisitor抛出类格式错误   java为什么在从ViewModel调用时,改型排队不起作用?   调试小程序Java控制台:删除跟踪消息大小限制   java复杂安卓活动动画   java如何在使用JDOM2解析XML时忽略注释内容   java通过循环创建文本字段   即使在bufferedwriter关闭后也未发现java文件异常   单链表恢复中的java错误