轻松地将函数转换为多命令程序。
clime的Python项目详细描述
此文档的完整版本位于clime.mosky.tw。
clime
clime允许您将任何模块转换为多命令cli程序 配置。
主要功能:
- 它在零配置下运行良好。把你从配置地狱中解放出来。
- docstring(即帮助文本)只是配置。当你完成你的 docstring,别名和元变量的配置也完成了。
- 它自动生成每个命令的用法。
对于大多数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描述了更多 关于它的工作原理。