Skip to content

Commit

Permalink
Make all paths supplied by flags absolute (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
SarahFrench authored Dec 12, 2024
1 parent fcceab6 commit 0c4ec7d
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions internal/cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ package cmd
import (
"errors"
"flag"
"os"
"path"
"path/filepath"
)

Expand Down Expand Up @@ -58,12 +56,28 @@ func ParseFlags(command string, args []string) (*Flags, error) {
// if the caller has asked to just execute the default Terraform system
// command/binary.
if !filepath.IsAbs(flags.TerraformBinaryPath) && flags.TerraformBinaryPath != "terraform" {
wd, err := os.Getwd()
path, err := filepath.Abs(flags.TerraformBinaryPath)
if err != nil {
return nil, err
}
flags.TerraformBinaryPath = path
}

flags.TerraformBinaryPath = path.Join(wd, flags.TerraformBinaryPath)
// Make directory paths absolute, too
if !filepath.IsAbs(flags.GoldenFilesDirectory) {
path, err := filepath.Abs(flags.GoldenFilesDirectory)
if err != nil {
return nil, err
}
flags.GoldenFilesDirectory = path
}

if !filepath.IsAbs(flags.TestingFilesDirectory) {
path, err := filepath.Abs(flags.TestingFilesDirectory)
if err != nil {
return nil, err
}
flags.TestingFilesDirectory = path
}

return &flags, nil
Expand Down

0 comments on commit 0c4ec7d

Please sign in to comment.