轻松地将函数转换为多命令程序。

clime的Python项目详细描述


https://travis-ci.org/moskytw/clime.pnghttps://pypip.in/v/clime/badge.pnghttps://pypip.in/d/clime/badge.png

此文档的完整版本位于clime.mosky.tw

clime

clime允许您将任何模块转换为多命令cli程序 配置。

主要功能:

  1. 它在零配置下运行良好。把你从配置地狱中解放出来。
  2. docstring(即帮助文本)只是配置。当你完成你的 docstring,别名和元变量的配置也完成了。
  3. 它自动生成每个命令的用法。

对于大多数cli来说,这是一个比重optparse或argparse更好的选择 任务。

叫我来!

我给你举个例子。

我们在这里有一个带有docstring的简单脚本:

# file: repeat.py

def repeat(message, times=2, count=False):
    '''It repeats the message.

    options:
        -m=<str>, --message=<str>  The description of this option.
        -t=<int>, --times=<int>
        -c, --count
    '''

    s = message * times
    return len(s) if count else s

添加此行后:

import clime.now

我们的cli程序已经准备好了!

$ python repeat.py twice
twicetwice

$ python repeat.py --times=3 thrice
thricethricethrice

它还为这个脚本生成了一个很好的用法:

$ python repeat.py --help
usage: [-t <int> | --times=<int>] [-c | --count] <message>
   or: repeat [-t <int> | --times=<int>] [-c | --count] <message>

如果您的函数中有docstring,它也会显示在使用手册中 --help

$ python repeat.py repeat --help
usage: [-t <int> | --times=<int>] [-c | --count] <message>
   or: repeat [-t <int> | --times=<int>] [-c | --count] <message>

It repeats the message.

options:
    -m=<str>, --message=<str>  The message.
    -t=<int>, --times=<int>
    -c, --count

您可以在clime/examples中找到更多示例。

Command描述了更多 关于它的工作原理。

安装

clime托管在两个不同的平台上,PyPIGitHub

从pypi安装

PyPI安装clime以获得稳定版本:

$ sudo pip install clime

如果没有pip,请执行

$ sudo apt-get install python-pip

在基于debian的linux发行版上安装pip。

从github获取clime

如果要使用最新版本的clime,请使用

$ git clone git://github.com/moskytw/clime.git

克隆clime存储库,或从GitHub手动下载。

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

推荐PyPI第三方库


热门话题
内部嵌套滚动视图的java Recyclerview?   返回空值的java MapPartitionFunction   java无法访问apache模块源代码中的系统定义的环境变量   java需要帮助确定用户输入的最大值和最小值   java检查文件是否存在,如果存在,则创建一个编号更高的新文件   针对许多不正确XML文档的XSD的XML验证在Java中不报告任何错误?   java有没有一种方法可以将json字符串甚至JSONObject发送给POSTMAN,而不在每个双引号前加斜杠?   java如何获得频域中两个音频信号的比率?   java 安卓 studio理解错误   java插入到部分填充的数组中   java使用流<String>创建流<CustomType>?   java开放式按键应用程序   java获取zxing生成的图像路径   使用shibboleth sso的java授权   java在运行时更改bean类名   javajooq如何从表中选择min'id'   java通过Eclipse web项目运行hadoop mapreduce字数   java同步方法与非同步方法同时执行   方法每次返回一个不同的加密字符数组   java获取ArrayList的每个元素中出现的特定字符的频率<String>