refactor out findBinary for kubeservice
@@ -2,7 +2,7 @@ package kubernetes
import (
"bytes"
- "errors"
+ "fmt"
"os"
"os/exec"
"path/filepath"
@@ -16,20 +16,7 @@ import (
// specified namespace and name) to the paths of resource definition
// files.
func FindDefinedServices(path string) (map[flux.ServiceID][]string, error) {
- bin, err := func() (string, error) {
- cwd, err := os.Getwd()
- if err != nil {
- return "", err
- }
- localBin := filepath.Join(cwd, "kubeservice")
- if _, err := os.Stat(localBin); err == nil {
- return localBin, nil
- }
- if pathBin, err := exec.LookPath("kubeservice"); err == nil {
- return pathBin, nil
- }
- return "", errors.New("kubeservice not found")
- }()
+ bin, err := findBinary("kubeservice")
if err != nil {
return nil, err
}
@@ -64,3 +51,18 @@ func FindDefinedServices(path string) (map[flux.ServiceID][]string, error) {
}
return services, nil
}
+
+func findBinary(name string) (string, error) {
+ cwd, err := os.Getwd()
+ if err != nil {
+ return "", err
+ }
+ localBin := filepath.Join(cwd, name)
+ if _, err := os.Stat(localBin); err == nil {
+ return localBin, nil
+ }
+ if pathBin, err := exec.LookPath(name); err == nil {
+ return pathBin, nil
+ }
+ return "", fmt.Errorf("%s not found", name)
+}
