- 授权协议: MIT
- 开发语言: Google Go
- 操作系统: 跨平台
- 软件首页: https://github.com/mkideal/cli
- 软件文档: https://github.com/mkideal/cli
软件介绍
cli是一个用go语言写成的用于快速构建go语言命令行程序的工具。
Key features
-
Lightweight and easy to use.
-
Defines flag by tag, e.g. flag name(short or/and long), description, default value, password, prompt and so on.
-
Type safety.
-
Output looks very nice.
-
Supports custom Validator.
-
Supports slice and map as a flag.
-
Supports any type as a flag field which implements cli.Decoder interface.
-
Supports any type as a flag field which use FlagParser.
-
Suggestions for command.(e.g. hl => help, "veron" => "version").
-
Supports default value for flag, even expression about env variable(e.g. dft:"$HOME/dev").
-
下图是用cli创建的示例程序gogo的帮助显示:
一个hello的例子
package main
import (
"github.com/mkideal/cli"
)
type argT struct {
Help bool `cli:"!h,help" usage:"display help information"`
Name string `cli:"name" usage:"your name" dft:"world"`
Age uint8 `cli:"a,age" usage:"your age" dft:"100"`
}
func main() {
cli.Run(&argT{}, func(ctx *cli.Context) error {
argv := ctx.Argv().(*argT)
if argv.Help {
ctx.String(ctx.Usage())
} else {
ctx.String("Hello, %s! Your age is %d?\n", argv.Name, argv.Age)
}
return nil
})
}
更多有用的例子:
http://www.mkideal.com/golang/cli-examples.html
