From 69052134317801a8fd9f3d17fd78d35842cf086f Mon Sep 17 00:00:00 2001 From: guonaihong Date: Wed, 8 Mar 2023 22:20:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EGetIndexEx=20(#105)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- clop.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/clop.go b/clop.go index e86ecc3..c5b0baa 100644 --- a/clop.go +++ b/clop.go @@ -211,23 +211,30 @@ func (c *Clop) IsSetSubcommand(subcommand string) bool { return ok } -func (c *Clop) GetIndex(optName string) uint64 { +// TODO 补充下更多单元测试 +func (c *Clop) GetIndexEx(optName string) (index uint64, ok bool) { // 长短选项 o, ok := c.shortAndLong[optName] if ok { - return o.index + return o.index, true } // args参数 if _, ok := c.checkArgs[optName]; ok { for _, o := range c.envAndArgs { if o.argsName == optName { - return o.index + return o.index, true } } } - return 0 + return 0, false + +} + +func (c *Clop) GetIndex(optName string) (index uint64) { + index, _ = c.GetIndexEx(optName) + return } func (c *Clop) setOption(name string, option *Option, m map[string]*Option, long bool) error {