Skip to content

Releases: guonaihong/clop

v0.1.4版本

11 Nov 04:45
4990007
Compare
Choose a tag to compare

#69
修改usage

v0.1.3版本

15 Aug 11:39
78cf51c
Compare
Choose a tag to compare

新增MustBind函数

v0.1.2版本

11 Jun 13:41
1eba648
Compare
Choose a tag to compare

#64 优化短选项出错后的提示信息

v0.1.1版本

01 Jun 14:55
Compare
Choose a tag to compare

#63

Parsing flag code to generate clop code

让你爽翻天, 如果你的command想迁移至clop, 但是全面众多的flag代码, 又不想花费太多时间在无谓的人肉code转换上, 这时候你就需要clop命令, 一行命令解决你的痛点.

1.安装clop命令

go get github.com/guonaihong/clop/cmd/clop

2.使用clop解析包含flag包的代码

就可以把main.go里面的flag库转成clop包的调用方式

clop -f main.go

main.go代码如下

package main

import "flag"

func main() {
	s := flag.String("string", "", "string usage")
	i := flag.Int("int", "", "int usage")
	flag.Parse()
}

输出代码如下

package main

import (
	"github.com/guonaihong/clop"
)

type flagAutoGen struct {
	Flag string `clop:"--string" usage:"string usage" `
	Flag int    `clop:"--int" usage:"int usage" `
}

func main() {
	var flagVar flagAutoGen
	clop.Bind(&flagVar)
}

v0.1.0版本

12 Apr 05:48
aa4752f
Compare
Choose a tag to compare

修复:使用tag,没有正确显示命令行选项命的问题。

v0.0.12版本

30 Mar 02:49
91da331
Compare
Choose a tag to compare

支持short和 long tag。
#58

package main

import (
    "fmt"
    "github.com/guonaihong/clop"
)

type cat struct {
	NumberNonblank bool `clop:"-c;long" 
	                     usage:"number nonempty output lines, overrides"`

	ShowEnds bool `clop:"-E;long" 
	               usage:"display $ at end of each line"`

	Number bool `clop:"-n;long" 
	             usage:"number all output lines"`

	SqueezeBlank bool `clop:"-s;long" 
	                   usage:"suppress repeated empty output lines"`

	ShowTab bool `clop:"-T;long" 
	              usage:"display TAB characters as ^I"`

	ShowNonprinting bool `clop:"-v;long" 
	                      usage:"use ^ and M- notation, except for LFD and TAB" `

	Files []string `clop:"args=files"`
}

func main() {
 	c := cat{}
	err := clop.Bind(&c)

	fmt.Printf("%#v, %s\n", c, err)
}

v0.0.11版本

19 Aug 15:11
9614852
Compare
Choose a tag to compare

see #55

支持如果输入错误选项,推荐正确的选项。

  • 示例代码
package main

import (
	"fmt"

	"github.com/guonaihong/clop"
)

type T struct {
	Num  int `clop:"--num" usage:"a"`
	Rate int `clop:"--rate" usage:"b"`
}

func main() {
	t := T{}
	clop.Bind(&t)
	fmt.Printf("%d:%d\n", clop.GetIndex("a"), clop.GetIndex("b"))

	fmt.Printf("%v\n", t)

}
  • 输出
./t --number
error: Found argument '--number' which wasn't expected, or isn't valid in this context
	Did you mean --num?

For more information try --help

v0.0.10版本

07 Jun 08:38
134f918
Compare
Choose a tag to compare

#50 支持单个'-'符号

v0.0.9版本

02 Jun 10:55
1cccff4
Compare
Choose a tag to compare

#51 Bind检测非指针类型

v0.0.8版本

19 May 12:55
744bebe
Compare
Choose a tag to compare

see #48 数据格式为数组时,清空default的数据