分享下从零实现一个命令解析器的所有细节。
https://github.com/guonaihong/clop
package main
import (
"fmt"
"github.com/guonaihong/clop"
)
type cat struct {
NumberNonblank bool `clop:"-c;--number-nonblank"
usage:"number nonempty output lines, overrides"`
ShowEnds bool `clop:"-E;--show-ends"
usage:"display $ at end of each line"`
Number bool `clop:"-n;--number"
usage:"number all output lines"`
SqueezeBlank bool `clop:"-s;--squeeze-blank"
usage:"suppress repeated empty output lines"`
ShowTab bool `clop:"-T;--show-tabs"
usage:"display TAB characters as ^I"`
ShowNonprinting bool `clop:"-v;--show-nonprinting"
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)
}
1
guonaihong OP 看来我发消息,要有个强劲的大心脏。一不小心就没人看了,哈哈。
|
2
unicloud 2020-02-17 16:45:15 +08:00
确实有点尴尬啊~哈哈
|
3
guonaihong OP @unicloud 这是在微笑在中掩示尴尬。。。哈哈
|
4
hijoker 2020-02-17 19:40:18 +08:00
加油,奥力给
|
5
guonaihong OP @hijoker 恩,加油,奥力给是啥意思?
|