Allow using unabiguous long option prefixes

This commit is contained in:
Kovid Goyal
2022-09-30 13:29:06 +05:30
parent 7d5849cc17
commit 74b1cac344
5 changed files with 60 additions and 3 deletions

View File

@@ -82,6 +82,19 @@ func (self *OptionGroup) AddOptionFromString(parent *Command, items ...string) (
return ans, err
}
func (self *OptionGroup) FindOptions(prefix_with_hyphens string) []*Option {
is_short := !strings.HasPrefix(prefix_with_hyphens, "--")
option_name := NormalizeOptionName(prefix_with_hyphens)
ans := make([]*Option, 0, 4)
for _, q := range self.Options {
if q.MatchingAlias(option_name, is_short) != "" {
ans = append(ans, q)
}
}
return ans
}
func (self *OptionGroup) FindOption(name_with_hyphens string) *Option {
is_short := !strings.HasPrefix(name_with_hyphens, "--")
option_name := NormalizeOptionName(name_with_hyphens)