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

internal/config: support waypoint.hcl.json for HCL-flavored JSON syntax #867

Merged
merged 2 commits into from
Dec 1, 2020
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
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