Skip to content

Commit

Permalink
新增GetIndexEx (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
guonaihong authored Mar 8, 2023
1 parent 1b203ed commit 6905213
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions clop.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6905213

Please sign in to comment.