Add various special purpose entry points

This commit is contained in:
Kovid Goyal
2022-11-14 15:41:58 +05:30
parent 3bf20594b7
commit c2a2b4c087
4 changed files with 57 additions and 4 deletions
+13 -3
View File
@@ -22,6 +22,12 @@ func (self *MatchGroup) add_match(word string, description ...string) *Match {
return &ans
}
func (self *MatchGroup) add_prefix_to_all_matches(prefix string) {
for _, m := range self.Matches {
m.Word = prefix + m.Word
}
}
type Completions struct {
Groups []*MatchGroup `json:"groups,omitempty"`
@@ -32,9 +38,7 @@ type Completions struct {
func (self *Completions) add_prefix_to_all_matches(prefix string) {
for _, mg := range self.Groups {
for _, m := range mg.Matches {
m.Word = prefix + m.Word
}
mg.add_prefix_to_all_matches(prefix)
}
}
@@ -77,6 +81,12 @@ type Command struct {
Subcommand_must_be_first bool
}
func (self *Command) clone_options_from(other *Command) {
for _, opt := range other.Options {
self.Options = append(self.Options, opt)
}
}
func (self *Command) add_group(name string) *CommandGroup {
for _, g := range self.Groups {
if g.Title == name {