declic(面向decorator的cli creator)是一个用于创建命令行界面的python 3小包

declic的Python项目详细描述


declic(面向decorator的cli creator)是一个用于 使用decorators创建命令行接口。它的灵感来自 这个click包基于argparse

安装

>;来自PYPI:

pip install declic

或来自github:

pip install git+https://github.com/Septaris/declic.git

用法

下面是declic用法的示例:

fromdeclicimportgroup,argument,command# on_before callbacks are executed if:# - the group itself is called# - if any of the child of the group is calleddefbefore_bar():print('before bar')defbefore_sub(tata):print('before sub: %s'%tata)# define the root command (a group)@group(description='my description',on_before=before_bar)@argument('--version',action='version',version='<the version>')@argument('--foo',type=int,default=1)defbar():print('bar')# define a sub-group@bar.group(invokable=True,on_before=before_sub)@argument('--toto',type=int,default=2)@argument('--tata',type=str,default='aaa')defsub(toto,tata):print('toto: %s'%toto)print('tata: %s'%tata)# define a sub-command of the sub-group# chain option allows to execute each parent group (if they are invokable) before the command call# each on_before functions will be executed anyway@sub.command(chain=True)defmop(toto,**kwargs):print('kwargs: %s'%kwargs)print('toto: %s'%toto)# define a sub-command of the root group@bar.command()@argument('-x',type=int,default=1)@argument('y',type=float)deffoo(x,y):print(x,y)if__name__=='__main__':importsysbar(sys.argv[1:])# or bar()

运行cli:

$ python my_file.py --help

usage: bar [-h] [--foo FOO] [--version] {sub_group,foo} ...

my description

positional arguments:
  {sub,foo}

optional arguments:
  -h, --help       show this help message and exit
  --foo FOO
  --version        show program's version number and exit

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

推荐PyPI第三方库


热门话题
java如何将字符串转换为自定义对象   java如何从socket方法获取数据?   Java中的soap读取回车和新行   java在单击时替换图像   java推荐的使用RXJava执行异步任务的方法   java MySql连接器JDBC驱动程序不支持连接池吗?   java将活动堆栈清理到顶部   java计数用户输入的数量   java从webservice下载大文件导致应用程序性能问题   JavaLocalDate。EPOCH不可用   java如何在使用Selenium等待一定时间后,在页面无法加载(get(url))时自动刷新页面   java Calendar setLenient方法不允许检查年份字段的健全性   java Eclipse和intelliJ 安卓 SDK问题   java为什么我可以在没有super关键字的情况下调用父方法?   java iText的PDF格式不好