"fmt"
"os"
"path/filepath"
+ "slices"
"strings"
"text/template"
groups: groupsMap,
allHosts: allHostsMap,
allGroups: allGroupsMap,
+ allGroupHosts: allGroups,
})
if err != nil {
return fmt.Errorf("%s: %v", path, err)
groups map[string]bool
allHosts map[string]bool
allGroups map[string]bool
+ allGroupHosts map[string][]string
}
// TODO: extend data passed to template
return t.Host == host
}
func (t *templateArgs) InGroup(group string) bool {
+ t.groupMustExist(group)
+ return t.groups[group]
+}
+
+func (t *templateArgs) GroupHosts(group string) []string {
+ t.groupMustExist(group)
+ x := t.allGroupHosts[group]
+ slices.Sort(x)
+ return x
+}
+
+func (t *templateArgs) groupMustExist(group string) {
// Don't permit invalid groups to detect typos; detected groups cannot be
// checked
if group != GroupAll &&
!strings.HasPrefix(group, GroupDetectedPrefix) {
panic(fmt.Sprintf("group %q does not exist", group))
}
- return t.groups[group]
}
// vi: set noet ts=4 sw=4 sts=4: