-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Hector Fernandez <[email protected]>
- Loading branch information
Showing
9 changed files
with
295 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package run | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
func GoModTidy(modroot string) (string, error) { | ||
log.Println("Running go mod tidy ...") | ||
cmd := exec.Command("go", "mod", "tidy") | ||
cmd.Dir = modroot | ||
if bytes, err := cmd.CombinedOutput(); err != nil { | ||
return strings.TrimSpace(string(bytes)), err | ||
} | ||
return "", nil | ||
} | ||
|
||
func GoGetModule(name, version, modroot string) (string, error) { | ||
cmd := exec.Command("go", "get", fmt.Sprintf("%s@%s", name, version)) //nolint:gosec | ||
cmd.Dir = modroot | ||
if bytes, err := cmd.CombinedOutput(); err != nil { | ||
return strings.TrimSpace(string(bytes)), err | ||
} | ||
return "", nil | ||
} | ||
|
||
func GoModEditReplaceModule(nameOld, nameNew, version, modroot string) (string, error) { | ||
cmd := exec.Command("go", "mod", "edit", "-dropreplace", nameOld) //nolint:gosec | ||
cmd.Dir = modroot | ||
if bytes, err := cmd.CombinedOutput(); err != nil { | ||
return strings.TrimSpace(string(bytes)), fmt.Errorf("Error running go command to drop replace modules: %w", err) | ||
} | ||
|
||
cmd = exec.Command("go", "mod", "edit", "-replace", fmt.Sprintf("%s=%s@%s", nameOld, nameNew, version)) //nolint:gosec | ||
cmd.Dir = modroot | ||
if bytes, err := cmd.CombinedOutput(); err != nil { | ||
return strings.TrimSpace(string(bytes)), fmt.Errorf("Error running go command to replace modules: %w", err) | ||
} | ||
return "", nil | ||
} | ||
|
||
func GoModEditDropRequireModule(name, modroot string) (string, error) { | ||
cmd := exec.Command("go", "mod", "edit", "-droprequire", name) //nolint:gosec | ||
cmd.Dir = modroot | ||
if bytes, err := cmd.CombinedOutput(); err != nil { | ||
return strings.TrimSpace(string(bytes)), err | ||
} | ||
|
||
return "", nil | ||
} | ||
|
||
func GoModEditRequireModule(name, version, modroot string) (string, error) { | ||
if bytes, err := GoModEditDropRequireModule(name, modroot); err != nil { | ||
return strings.TrimSpace(string(bytes)), err | ||
} | ||
|
||
cmd := exec.Command("go", "mod", "edit", "-require", fmt.Sprintf("%s@%s", name, version)) //nolint:gosec | ||
cmd.Dir = modroot | ||
if bytes, err := cmd.CombinedOutput(); err != nil { | ||
return strings.TrimSpace(string(bytes)), err | ||
} | ||
return "", nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package types | ||
|
||
type Package struct { | ||
OldName string | ||
Name string | ||
Version string | ||
Replace bool | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module github.com/puerco/hello | ||
|
||
go 1.19 | ||
|
||
require github.com/sirupsen/logrus v1.8.0 | ||
|
||
require ( | ||
github.com/magefile/mage v1.10.0 // indirect | ||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/magefile/mage v1.10.0 h1:3HiXzCUY12kh9bIuyXShaVe529fJfyqoVM42o/uom2g= | ||
github.com/magefile/mage v1.10.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/sirupsen/logrus v1.8.0 h1:nfhvjKcUMhBMVqbKHJlk5RPrrfYr/NMo3692g0dwfWU= | ||
github.com/sirupsen/logrus v1.8.0/go.mod h1:4GuYW9TZmE769R5STWrRakJc4UqQ3+QQ95fyz7ENv1A= | ||
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= | ||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= | ||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ= | ||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
Copyright 2022 Puerco J. Cerdo | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func main() { | ||
logrus.Info("preparing to say hi...") | ||
fmt.Println("Hello World!") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.