Releases: guonaihong/clop
Releases · guonaihong/clop
v0.2.2版本
v0.2.1版本
请看#59
这个版本, 增强子命令模式的易用性.
package main
import (
"fmt"
"github.com/guonaihong/clop"
)
type add struct {
All bool `clop:"-A; --all" usage:"add changes from all tracked and untracked files"`
Force bool `clop:"-f; --force" usage:"allow adding otherwise ignored files"`
Pathspec []string `clop:"args=pathspec"`
}
func (a *add) SubMain() {
// 当add子命令被设置时
// clop会自动调用这个函数
}
type mv struct {
Force bool `clop:"-f; --force" usage:"allow adding otherwise ignored files"`
}
func (m *mv) SubMain() {
// 当mv 子命令被设置时
// clop会自动调用这个函数
}
type git struct {
Add add `clop:"subcommand=add" usage:"Add file contents to the index"`
Mv mv `clop:"subcommand=mv" usage:"Move or rename a file, a directory, or a symlink"`
}
func main() {
g := git{}
clop.Bind(&g)
}
v0.1.12版本
v0.1.11版本
出发点
对于如下代码, 如果不填写任何选项, 可以正确提示, 提示也比较友好
./main
error: --long must have a value!
For more information try --help
但是如何写了长选项, 但是没有值.
./main --long
就变成了
./main --long
wrong long option
For more information try --help
这时候的提示信息太少, 现在的提示信息较少, 不方便debug.
现需要, ./main --long的时候也提示
error: --long must have a value!
For more information try --help
package main
import "github.com/guonaihong/clop"
type test struct {
Long int `clop:"long" valid:"required"`
}
func main() {
t := test{}
clop.MustBind(&t)
}
v0.1.10版本
有重复选项注册时, 目前提示消息如下:
-n is already in use
现优化为
-n is already in use, duplicate definition with -n,--number
v0.1.9版本
v0.1.8版本
本次版本增强环境变量的用法
使用env tag会根据结构体名, 生成一个环境变量名, 规则就是驼峰命令名, 改成大写下划线
// file name use_env.go
package main
import (
"fmt"
"github.com/guonaihong/clop"
)
type env struct {
OmpNumThread string `clop:"env" usage:"omp num thread"`
Xpath string `clop:"env" usage:"xpath"`
Max int `clop:"env" usage:"max thread"`
}
func main() {
e := env{}
clop.Bind(&e)
fmt.Printf("%#v\n", e)
}
// run
// env XPATH=`pwd` OMP_NUM_THREAD=3 MAX=4 ./use_env
// output
// main.env{OmpNumThread:"3", Xpath:"/home/guo", Max:4}
v0.1.7版本
修复v0.1.6版本新加的结构体串联功能, 非最后一个结构体, 不支持数据校验的现象.
v0.1.6版本
新增结构体串联功能
多结构体串联功能. 多结构体统一组成一个命令行视图
如果命令行解析是要怼到多个(>=2)结构体里面, 可以使用结构体串联功能, 前面几个结构体使用clop.Register()
接口, 最后一个结构体使用clop.Bind()
函数.
/*
┌────────────────┐
│ │
│ │
│ ServerAddress │ ┌─────────────────────┐
├────────────────┤ │ │
│ │ ──────────────────► │ │
│ │ │ clop.MustRegitser()│
│ Rate │ │ │
│ │ └─────────────────────┘
└────────────────┘
┌────────────────┐
│ │
│ ThreadNum │
│ │ ┌─────────────────────┐
│ │ │ │
├────────────────┤ ──────────────────► │ │
│ │ │ clop.Bind() │
│ OpenVad │ │ │
│ │ │ │
└────────────────┘ └─────────────────────┘
*/
type Server struct {
ServerAddress string `clop:"long" usage:"Server address"`
Rate time.Duration `clop:"long" usage:"The speed at which audio is sent"`
}
type Asr struct{
ThreadNum int `clop:"long" usage:"thread number"`
OpenVad bool `clop:"long" usage:"open vad"`
}
func main() {
asr := Asr{}
ser := Server{}
clop.MustRegister(&asr)
clop.Bind(&ser)
}
// 可以使用如下命令行参数测试下效果
// ./example --server-address", ":8080", "--rate", "1s", "--thread-num", "20", "--open-vad"