Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #867 from hashicorp/f-json
Browse files Browse the repository at this point in the history
internal/config: support waypoint.hcl.json for HCL-flavored JSON syntax
  • Loading branch information
mitchellh authored Dec 1, 2020
2 parents ac96ee4 + 6ad34b7 commit 4e0eae9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion internal/cli/base_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
19 changes: 18 additions & 1 deletion internal/config/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -29,13 +33,26 @@ 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
} else if !os.IsNotExist(err) {
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
Expand Down
6 changes: 3 additions & 3 deletions internal/runner/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4e0eae9

Please sign in to comment.