Skip to content

Commit

Permalink
modulegen: create internal/module (#1505)
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
  • Loading branch information
mmorel-35 committed Aug 24, 2023
1 parent 98ceaee commit 94c8cb6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
19 changes: 19 additions & 0 deletions modulegen/internal/tools/exec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package tools

import (
"os/exec"
)

func GoModTidy(cmdDir string) error {
return runGoCommand(cmdDir, "mod", "tidy")
}

func GoVet(cmdDir string) error {
return runGoCommand(cmdDir, "vet", "./...")
}

func runGoCommand(cmdDir string, args ...string) error {
cmd := exec.Command("go", args...)
cmd.Dir = cmdDir
return cmd.Run()
}
12 changes: 3 additions & 9 deletions modulegen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"html/template"
"os"
"os/exec"
"path/filepath"
"regexp"
"sort"
Expand All @@ -18,6 +17,7 @@ import (

"github.com/testcontainers/testcontainers-go/modulegen/internal/dependabot"
"github.com/testcontainers/testcontainers-go/modulegen/internal/mkdocs"
"github.com/testcontainers/testcontainers-go/modulegen/internal/tools"
)

var (
Expand Down Expand Up @@ -155,12 +155,12 @@ func main() {
}

cmdDir := filepath.Join(ctx.RootDir, example.ParentDir(), example.Lower())
err = runGoCommand(cmdDir, "mod", "tidy")
err = tools.GoModTidy(cmdDir)
if err != nil {
fmt.Printf(">> error synchronizing the dependencies: %v\n", err)
os.Exit(1)
}
err = runGoCommand(cmdDir, "vet", "./...")
err = tools.GoVet(cmdDir)
if err != nil {
fmt.Printf(">> error checking generated code: %v\n", err)
os.Exit(1)
Expand Down Expand Up @@ -338,12 +338,6 @@ func getModulesOrExamplesAsString(t bool) (string, error) {
return strings.Join(names, ", "), nil
}

func runGoCommand(cmdDir string, args ...string) error {
cmd := exec.Command("go", args...)
cmd.Dir = cmdDir
return cmd.Run()
}

func getRootDir() (string, error) {
current, err := os.Getwd()
if err != nil {
Expand Down

0 comments on commit 94c8cb6

Please sign in to comment.