FauxCLI:从给定的 YAML 文件模拟命令行客户端

FauxCLI(发音foak-ley)从给定的YAML文件模拟一个命令行客户端。

快速开始

安装:

$gogetgithub.com/nextrevision/fauxcli

在当前目录创建一个cli.yaml文件:

name:spiderpighelp:doeswhateveraspiderpigdoescommands:-name:swinghelp:swingsfromaweboutput:|Ican'tdothat,I'mapig!-name:plophelp:supersecretmaneuveroutput:|Lookout!

运行fauxcli:

$fauxclidoeswhateveraspiderpigdoesUsage:spiderpig[command]AvailableCommands:swingswingsfromawebplopsupersecretmaneuverFlags:-h,--helphelpforspiderpigUse"spiderpig[command]--help"formoreinformationaboutacommand.

子命令:

$fauxcliswingIcan'tdothat,I'mapig!

别名:

$aliasspiderpig='fauxcli'$spiderpigplopLookout!

安装

go:

gogetgithub.com/nextrevision/fauxcli

使用GitHub版本:

#OSXcurl-s-o/usr/local/bin/fauxcli#Linuxcurl-s-o/usr/local/bin/fauxcli+x/usr/local/bin/fauxcli

cli.yaml

---#(required)nameofthecommandname:mycliapp#(required)thehelptextforthecommand(displayedwith-h)help:doessomethingcool#additionalcommandaliasesaliases:["myapp","app"]#outputtoprintwhenthecommandisrun#ifthiskeyisomitted,thecommandwillactasa#parenttoanysubcommands,essentiallydoingnothing#butprintingthehelptextoutput:|Hello,World!#flagsavailabletothecommandflags:#(required)longnameoftheflag(--debug)-name:debug#(required)helptextfortheflaghelp:enablesdebugging#shortnamefortheflag(-d)short:d#defaultvalueoftheflagdefault:false#maketheflaggloballyavailableglobal:true#thetypeofthevalue(defaultstring)#availabletypes:#-string#-bool#-int#-floattype:bool#subcommands(nestedfromalltheoptionsabove)commands:-name:subcommand1help:asubcommandflags:-name:upperhelp:convertsoutputtouppercaseshort:utype:booloutput:|{{if.Flags.upper.Bool-}}HELLOFROMSC1!{{else-}}HellofromSC1!{{end-}}-name:subcommand2help:anothersubcommandwithchildrencommands:-name:child1help:thefirstchildcommandoutput:|Hellofromchild1-name:child2help:thesecondchildcommandoutput:|Hellofromchild2

FauxCLI使用Go编写,託管在GitHub:

微信订阅号:开源派(opensourcepie)

↓点击阅读原文,查看相关连结