2023-11-05 01:28:11 +00:00
|
|
|
package main
|
2023-11-03 04:41:05 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2023-11-05 01:28:11 +00:00
|
|
|
func VersionStringToStruct(version string) VersionTag {
|
|
|
|
splitVersion := strings.Split(version, ".")
|
|
|
|
|
|
|
|
return VersionTag{Major: splitVersion[0], Minor: splitVersion[1], Patch: splitVersion[2]}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ValidateVersion(version string) error {
|
2023-11-03 04:41:05 +00:00
|
|
|
if splitVersion := strings.Split(version, "."); len(splitVersion) != 3 {
|
|
|
|
return errors.New("Invalid version string. Expected format 'a.b.c'.")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-11-27 23:16:57 +00:00
|
|
|
// RunCommand is a thin wrapper around running command-line calls
|
|
|
|
// programmatically. It abstracts common configuration like routing
|
|
|
|
// output and handling the directory the calls are made from.
|
2023-11-03 04:41:05 +00:00
|
|
|
func RunCommand(command []string, cwd string, quiet bool) (string, error) {
|
|
|
|
cmd := exec.Command(command[0], command[1:]...)
|
|
|
|
|
|
|
|
cmd.Dir = cwd
|
|
|
|
|
2023-11-27 23:16:57 +00:00
|
|
|
var out strings.Builder
|
|
|
|
var errOut strings.Builder
|
|
|
|
|
2023-11-03 04:41:05 +00:00
|
|
|
if !quiet {
|
|
|
|
cmd.Stdout = os.Stdout
|
|
|
|
cmd.Stderr = os.Stderr
|
2023-11-27 23:16:57 +00:00
|
|
|
} else {
|
|
|
|
cmd.Stdout = &out
|
|
|
|
cmd.Stderr = &errOut
|
2023-11-03 04:41:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := cmd.Run(); err != nil {
|
2023-11-27 23:16:57 +00:00
|
|
|
return errOut.String(), err
|
2023-11-03 04:41:05 +00:00
|
|
|
}
|
|
|
|
|
2023-11-27 23:16:57 +00:00
|
|
|
return out.String(), nil
|
2023-11-03 04:41:05 +00:00
|
|
|
}
|