7 Star 44 Fork 4

小蚂蚁 / clop

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
maybe_opt.go 702 Bytes
一键复制 编辑 原始数据 按行查看 历史
guonaihong 提交于 2022-04-04 21:24 . fix86 (#87)
package clop
import (
"fmt"
"github.com/antlabs/strsim"
)
func (c *Clop) maybeOpt(optionName string) string {
opts := make([]string, len(c.shortAndLong))
index := 0
for k := range c.shortAndLong {
opts[index] = k
index++
}
// 没有长短命令的直接返回
if len(opts) == 0 {
return ""
}
m := strsim.FindBestMatchOne(optionName, opts)
if m.Score > 0.0 {
return m.S
}
return ""
}
func (c *Clop) genMaybeHelpMsg(optionName string) string {
if s := c.maybeOpt(optionName); len(s) > 0 {
return fmt.Sprintf("\n Did you mean --%s?\n", s)
}
if _, ok := c.subcommand[optionName]; ok {
return fmt.Sprintf("\n Did you mean '%s' subcommand?\n", optionName)
}
return ""
}
Go
1
https://gitee.com/guonaihong/clop.git
git@gitee.com:guonaihong/clop.git
guonaihong
clop
clop
master

搜索帮助