From ecb0d11088a3cd7dcbba8598873d563ac1ce93ad Mon Sep 17 00:00:00 2001 From: adisbladis Date: Sat, 28 May 2022 22:52:14 +0800 Subject: [PATCH] generate: Set correct working directory for go mod download --- generate/generate.go | 10 +++++++--- main.go | 4 +--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/generate/generate.go b/generate/generate.go index c9d88f9..3ca63cb 100644 --- a/generate/generate.go +++ b/generate/generate.go @@ -8,6 +8,7 @@ import ( "io" "io/ioutil" "os/exec" + "path/filepath" "sort" "sync" @@ -29,7 +30,8 @@ type goModDownload struct { GoModSum string } -func GeneratePkgs(goModPath string, goMod2NixPath string) ([]*schema.Package, error) { +func GeneratePkgs(directory string, goMod2NixPath string) ([]*schema.Package, error) { + goModPath := filepath.Join(directory, "go.mod") log.WithFields(log.Fields{ "modPath": goModPath, @@ -57,9 +59,11 @@ func GeneratePkgs(goModPath string, goMod2NixPath string) ([]*schema.Package, er { log.Info("Downloading dependencies") - stdout, err := exec.Command( + cmd := exec.Command( "go", "mod", "download", "--json", - ).Output() + ) + cmd.Dir = directory + stdout, err := cmd.Output() if err != nil { return nil, err } diff --git a/main.go b/main.go index 114c71a..a0f3726 100644 --- a/main.go +++ b/main.go @@ -21,11 +21,9 @@ func main() { outDir = *directory } - goModPath := filepath.Join(*directory, "go.mod") - goMod2NixPath := filepath.Join(outDir, "gomod2nix.toml") outFile := goMod2NixPath - pkgs, err := generate.GeneratePkgs(goModPath, goMod2NixPath) + pkgs, err := generate.GeneratePkgs(*directory, goMod2NixPath) if err != nil { panic(err) }