ec-一个用于python模块的cli接口。

ec的Python项目详细描述


意图

EC-打算减少通过命令行公开功能所需的学习曲线。有了像argparsedocopt这样的可用选项,可能需要几个小时才能使它们正确。还有一个问题是需要额外的编码来设置和处理参数。请参见下面的示例,了解ec如何解决该问题。

一个简单的例子

fromec.ecimporttask@taskdefsay_hello():print'Hello, world!'

可以从命令行访问,例如:

$ python hello.py say_hello
        Hello, world!

功能

  • 类型化参数。
  • 子命令(如git)。
  • 自定义类型。
  • shell模式(类似于python的交互模式)。
  • 命名/位置参数。

更完整的示例

发件人:simple.py

fromec.ecimporttask,arg,group@task# define a task@arg(type=int,desc='Value for arg1')# add an argument with a type and a description@arg(type=int)deftask1(arg1,arg2=1):printarg1,arg2@group(desc='A group with some tasks')# define a groupclassgroup1:@taskdeftask1(arg1):# define a task inside the groupprintarg1+arg1

执行任务:<;分派模式>;

从命令行中输入

$ python simple.py task1 arg1=1arg2=212

$ python simple.py group1/task1 arg1=12

$ python simple.py group1/task1 1# positional arguments too are supported
2

交互执行任务:<;外壳模式>;

从命令行中输入

$ python simple.py # this will enter into ec-shell

>task1
Value for arg1: 1
arg2 (1): 212

>group1/task1 # execute task1 under group1
arg1: 111

>task1 arg1=1# arguments can be given while calling the task, the missing arguments will be collected from the user
arg2 (1): 212

>^Z # exit the shell

利用stdin:

从命令行中输入

$ echo12| xargs python simple.py task1 # Dispatch a command with args passed through STDIN and converted to args using xargs.
$ echo -e "1\n2"| python simple.py -p task1 # Dispatch a command and with partial args and pass the rest through STDIN.
$ echo task1 12| python simple.py # Feeding the shell with complete commands through stdin.

详细的文档可以在PyDocs找到。

有关更多示例,请查看github页。

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

推荐PyPI第三方库


热门话题
servlets Java EE+GlassFish:如果用户在其他地方登录,则强制用户注销   java在不更改源代码的情况下添加钩子   安卓 Java TextView Onclick()返回表达式错误   java Excel文件未使用Apache存储内部内存   java getRowCount()和getSelectedColumn()不起作用   无法在java中生成视图绑定。util。Android Gradle插件2.1的NoTouchElementException   Java中的类型转换运算符百分比计算为零   主java中的调用方法   java在Javasound中播放多个示例   java如何知道webDriver成功打开URL   java jmock,每次调用时返回新对象   eclipse使用Java在Selenium WebDriver中生成可执行文件   macos捆绑Java OS X应用程序默认为MacRoman编码   java我应该把我的休息网关变成一个图书馆吗?   java Eclipse插件:查找包含子字符串的行号无效   Java IOException:在Linux上发送UDP数据包时没有可用的缓冲区空间   java无法解析jaxbxjc2中的名称“xjc:globalJavaType”。2.52.罐子   java是否有HibernateAPI来检查是否创建了数据库?