Skip to content
Merged
Show file tree
Hide file tree
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
42 changes: 15 additions & 27 deletions hive.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,25 +117,28 @@ func main() {

// Parse the client list.
// It can be supplied as a comma-separated list, or as a YAML file.
checkFlagsExclusive("client", "client-file")
var clientList []libhive.ClientDesignator
if *clientsFile != "" {
clientList, err = parseClientsFile(&inv, *clientsFile)
if *clientsFile == "" {
clientList, err = libhive.ParseClientList(&inv, *clients)
if err != nil {
fatal("-client-file:", err)
fatal("-client:", err)
}
} else {
clientList, err = libhive.ParseClientList(&inv, *clients)
clientList, err = parseClientsFile(&inv, *clientsFile)
if err != nil {
fatal("-client:", err)
fatal("-client-file:", err)
}
// If YAML file is used, the list can be filtered by the -client flag.
if flagIsSet("client") {
filter := strings.Split(*clients, ",")
clientList = libhive.FilterClients(clientList, filter)
}
}

// Build clients and simulators.
if err := runner.Build(ctx, clientList, simList); err != nil {
fatal(err)
}

if *simDevMode {
runner.RunDevMode(ctx, env, *simDevModeAPIEndpoint)
return
Expand Down Expand Up @@ -175,27 +178,12 @@ func parseClientsFile(inv *libhive.Inventory, file string) ([]libhive.ClientDesi
return libhive.ParseClientListYAML(inv, f)
}

func checkFlagsExclusive(flagNames ...string) {
set := make(map[string]bool)
flag.Visit(func(f *flag.Flag) {
set[f.Name] = true
})
func flagIsSet(name string) bool {
var found bool
for _, name := range flagNames {
if set[name] {
if found {
fatal("flags", flagListString(flagNames), "cannot be used together")
}
flag.Visit(func(f *flag.Flag) {
if f.Name == name {
found = true
set[name] = false
}
}
}

func flagListString(names []string) string {
flags := make([]string, len(names))
for i := range flags {
flags[i] = "-" + names[i]
}
return strings.Join(flags, ", ")
})
return found
}
15 changes: 15 additions & 0 deletions internal/libhive/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,21 @@ func ParseClientListYAML(inv *Inventory, file io.Reader) ([]ClientDesignator, er
return res, nil
}

// FilterClients trims the given list to only include clients matching the 'filter list'.
func FilterClients(list []ClientDesignator, filter []string) []ClientDesignator {
accept := make(set[string])
for _, f := range filter {
accept.add(strings.TrimSpace(f))
}
var res []ClientDesignator
for _, c := range list {
if accept.contains(c.Client) || accept.contains(c.Name()) {
res = append(res, c)
}
}
return res
}

var knownBuildArgs = map[string]struct{}{
"tag": {}, // this is the branch/version specifier when pulling the git repo or docker base image
"github": {}, // (for git pull) github repo to clone
Expand Down