Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,22 @@ func GetAllStrict(alias, key string) ([]string, error) {
return DefaultUserSettings.GetAllStrict(alias, key)
}

// GetHosts returns all hosts in the configurations as well as any included ones.
func (u *UserSettings) GetHosts() []*Host {
u.doLoadConfigs()
hosts := make([]*Host, 0)
if u.systemConfig != nil {
hosts = append(hosts, u.systemConfig.GetHosts()...)
}
if u.userConfig != nil {
hosts = append(hosts, u.userConfig.GetHosts()...)
}
if u.customConfig != nil {
hosts = append(hosts, u.customConfig.GetHosts()...)
}
return hosts
}

// Get finds the first value for key within a declaration that matches the
// alias. Get returns the empty string if no value was found, or if IgnoreErrors
// is false and we could not parse the configuration file. Use GetStrict to
Expand Down Expand Up @@ -407,6 +423,23 @@ func (c *Config) Get(alias, key string) (string, error) {
return "", nil
}

// GetHosts returns all hosts in the configuration as well as any included ones.
func (c *Config) GetHosts() []*Host {
hosts := c.Hosts
for _, host := range c.Hosts {
for _, node := range host.Nodes {
switch t := node.(type) {
case *Include:
// TODO locking required? (t.mu.Lock())
for _, cfg := range t.files {
hosts = append(hosts, cfg.GetHosts()...)
}
}
}
}
return hosts
}

// GetAll returns all values in the configuration that match the alias and
// contains key, or nil if none are present.
func (c *Config) GetAll(alias, key string) ([]string, error) {
Expand Down