diff --git a/internal/cli/base_init.go b/internal/cli/base_init.go index 524cbc435dc..9816cf568f6 100644 --- a/internal/cli/base_init.go +++ b/internal/cli/base_init.go @@ -38,7 +38,7 @@ func (c *baseCommand) initConfig(optional bool) (*configpkg.Config, error) { // initConfigPath returns the configuration path to load. func (c *baseCommand) initConfigPath() (string, error) { - path, err := configpkg.FindPath("", "") + path, err := configpkg.FindPath("", "", true) if err != nil { return "", fmt.Errorf("Error looking for a Waypoint configuration: %s", err) } diff --git a/internal/config/path.go b/internal/config/path.go index 53954c904ee..c441a82d617 100644 --- a/internal/config/path.go +++ b/internal/config/path.go @@ -15,7 +15,11 @@ const Filename = "waypoint.hcl" // // If start is empty, start will be the current working directory. If // filename is empty, it will default to the Filename constant. -func FindPath(start, filename string) (string, error) { +// +// If searchParent is false, then we will not search parent directories +// and require the Waypoint configuration file be directly in the "start" +// directory. +func FindPath(start, filename string, searchParent bool) (string, error) { var err error if start == "" { start, err = os.Getwd() @@ -29,6 +33,7 @@ func FindPath(start, filename string) (string, error) { } for { + // Look for HCL syntax path := filepath.Join(start, filename) if _, err := os.Stat(path); err == nil { return path, nil @@ -36,6 +41,18 @@ func FindPath(start, filename string) (string, error) { return "", err } + // Look for JSON + path += ".json" + if _, err := os.Stat(path); err == nil { + return path, nil + } else if !os.IsNotExist(err) { + return "", err + } + + if !searchParent { + return "", nil + } + next := filepath.Dir(start) if next == start { return "", nil diff --git a/internal/runner/operation.go b/internal/runner/operation.go index aad66dfcfa7..5011f6b453b 100644 --- a/internal/runner/operation.go +++ b/internal/runner/operation.go @@ -31,9 +31,9 @@ func (r *Runner) executeJob( ) (*pb.Job_Result, error) { // Eventually we'll need to extract the data source. For now we're // just building for local exec so it is the working directory. - path := configpkg.Filename - if wd != "" { - path = filepath.Join(wd, path) + path, err := configpkg.FindPath(wd, "", false) + if err != nil { + return nil, err } // Determine the evaluation context we'll be using