diff --git a/main.go b/main.go index 52e2d31..9fa2c01 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "strings" "github.com/alexflint/go-arg" + "github.com/go-cmd/cmd" "go.wit.com/lib/gui/shell" "go.wit.com/lib/protobuf/forgepb" "go.wit.com/log" @@ -70,12 +71,31 @@ func main() { shell.RunQuiet([]string{"go", "mod", "edit", "-go=1.18"}) // TODO: make this a global } - // TODO: switch to using forgepb - // switch to forgepb - os.Setenv("GO111MODULE", "off") // keeps go list working if go version is back versioned for compatability - cmd := []string{"go", "list", "-f", "'{{.Name}}'"} - result := shell.RunQuiet(cmd) - os.Unsetenv("GO111MODULE") + var result cmd.Status + var cmd []string + if forge.IsGoWork() { + cmd = []string{"go", "work", "use"} + result = shell.Run(cmd) + log.Info(strings.Join(result.Stdout, "\n")) + log.Info(strings.Join(result.Stderr, "\n")) + if !shell.Exists("go.mod") { + cmd = []string{"go", "mod", "init"} + result = shell.Run(cmd) + log.Info(strings.Join(result.Stdout, "\n")) + log.Info(strings.Join(result.Stderr, "\n")) + } + cmd = []string{"go", "list", "-f", "'{{.Name}}'"} + result = shell.Run(cmd) + log.Info(strings.Join(result.Stdout, "\n")) + log.Info(strings.Join(result.Stderr, "\n")) + } else { + // TODO: switch to using forgepb + // switch to forgepb + os.Setenv("GO111MODULE", "off") // keeps go list working if go version is back versioned for compatability + cmd = []string{"go", "list", "-f", "'{{.Name}}'"} + result = shell.RunQuiet(cmd) + os.Unsetenv("GO111MODULE") + } packageName := strings.Join(result.Stdout, "\n") packageName = strings.TrimSpace(packageName) diff --git a/sort.go b/sort.go index fe06e31..d8a3aa0 100644 --- a/sort.go +++ b/sort.go @@ -81,7 +81,6 @@ func header(w io.Writer, names map[string]string) { headerComment(w) fmt.Fprintln(w, "import (") fmt.Fprintln(w, " \"fmt\"") - fmt.Fprintln(w, " \"os\"") fmt.Fprintln(w, " \"sort\"") fmt.Fprintln(w, " \"sync\"") fmt.Fprintln(w, ")")