Fix a bug where an empty target would return no results

This commit is contained in:
2022-01-13 23:45:56 +01:00
parent 1cab1df125
commit 6e69b9f789

View File

@@ -6,6 +6,7 @@ import (
"github.com/antonmedv/expr" "github.com/antonmedv/expr"
"github.com/apex/log" "github.com/apex/log"
"github.com/pkg/errors"
"github.com/speedrunsh/speedrun/pkg/common/cryptoutil" "github.com/speedrunsh/speedrun/pkg/common/cryptoutil"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
@@ -40,14 +41,15 @@ func GetInstances(target string) ([]Instance, error) {
} }
subset, err := filter(instances, target) subset, err := filter(instances, target)
if err != nil {
return nil, err
}
if len(subset) == 0 { if len(subset) == 0 {
return nil, fmt.Errorf("no instances found") return nil, fmt.Errorf("no instances found")
} }
if err != nil {
err = errors.Wrap(err, "could not filter instance list")
return nil, err
}
return subset, nil return subset, nil
} }
@@ -67,6 +69,10 @@ func SetupTLS() (*tls.Config, error) {
} }
func filter(instnces []Instance, target string) ([]Instance, error) { func filter(instnces []Instance, target string) ([]Instance, error) {
if target == "" {
return instnces, nil
}
var subset []Instance var subset []Instance
program, err := expr.Compile(target, expr.Env(Instance{}), expr.AsBool()) program, err := expr.Compile(target, expr.Env(Instance{}), expr.AsBool())