Clikt是一个Kotli库,Kotli的命令行接口,能够使编写命令行接口变得简洁直观,同时支持各种各样的用例,并允许在需要时进行高级定制。
Clikt的特点:
可以任意嵌套命令可组合,类型安全的参数值支持多种命令行接口风格JVM,NodeJS和本机Liux,Widows和MacOS的多平台软件包
示例代码:
classHello:CliktCommad(){valcout:Itbyoptio(help="Numberofgreetigs").it().default(1)valame:Strigbyoptio(help="Thepersotogreet").prompt("Yourame")overridefuru(){for(ii1..cout){echo("Hello$ame!")}}}fumai(args:Array<Strig>)=Hello().mai(args)运行结果:
$./hello--cout=3Yourame:JohHelloJoh!HelloJoh!HelloJoh!自动生成帮助参数:
$./hello--helpUsage:hello[OPTIONS]Optios:--coutINTNumberofgreetigs--ameTEXTThepersotogreet-h,--helpShowthismessageadexit错误处理:
$./hello--whoopsUsage:hello[OPTIONS]Error:osuchoptio:"--whoops".










评论