try to fix this when working in a go.work env
This commit is contained in:
parent
21ab45b3f5
commit
c3d018df22
24
main.go
24
main.go
|
@ -9,6 +9,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/alexflint/go-arg"
|
"github.com/alexflint/go-arg"
|
||||||
|
"github.com/go-cmd/cmd"
|
||||||
"go.wit.com/lib/gui/shell"
|
"go.wit.com/lib/gui/shell"
|
||||||
"go.wit.com/lib/protobuf/forgepb"
|
"go.wit.com/lib/protobuf/forgepb"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
|
@ -70,12 +71,31 @@ func main() {
|
||||||
shell.RunQuiet([]string{"go", "mod", "edit", "-go=1.18"}) // TODO: make this a global
|
shell.RunQuiet([]string{"go", "mod", "edit", "-go=1.18"}) // TODO: make this a global
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
// TODO: switch to using forgepb
|
||||||
// switch to forgepb
|
// switch to forgepb
|
||||||
os.Setenv("GO111MODULE", "off") // keeps go list working if go version is back versioned for compatability
|
os.Setenv("GO111MODULE", "off") // keeps go list working if go version is back versioned for compatability
|
||||||
cmd := []string{"go", "list", "-f", "'{{.Name}}'"}
|
cmd = []string{"go", "list", "-f", "'{{.Name}}'"}
|
||||||
result := shell.RunQuiet(cmd)
|
result = shell.RunQuiet(cmd)
|
||||||
os.Unsetenv("GO111MODULE")
|
os.Unsetenv("GO111MODULE")
|
||||||
|
}
|
||||||
|
|
||||||
packageName := strings.Join(result.Stdout, "\n")
|
packageName := strings.Join(result.Stdout, "\n")
|
||||||
packageName = strings.TrimSpace(packageName)
|
packageName = strings.TrimSpace(packageName)
|
||||||
|
|
1
sort.go
1
sort.go
|
@ -81,7 +81,6 @@ func header(w io.Writer, names map[string]string) {
|
||||||
headerComment(w)
|
headerComment(w)
|
||||||
fmt.Fprintln(w, "import (")
|
fmt.Fprintln(w, "import (")
|
||||||
fmt.Fprintln(w, " \"fmt\"")
|
fmt.Fprintln(w, " \"fmt\"")
|
||||||
fmt.Fprintln(w, " \"os\"")
|
|
||||||
fmt.Fprintln(w, " \"sort\"")
|
fmt.Fprintln(w, " \"sort\"")
|
||||||
fmt.Fprintln(w, " \"sync\"")
|
fmt.Fprintln(w, " \"sync\"")
|
||||||
fmt.Fprintln(w, ")")
|
fmt.Fprintln(w, ")")
|
||||||
|
|
Loading…
Reference in New Issue