pkg/utils: Add function to parse the user-specified release string
https://github.com/containers/toolbox/pull/318
This commit is contained in:
parent
9e2825524a
commit
43082145a9
|
|
@ -24,6 +24,7 @@ import (
|
||||||
"os/user"
|
"os/user"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
|
@ -269,6 +270,27 @@ func ShortID(id string) string {
|
||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ParseRelease(str string) (string, error) {
|
||||||
|
var release string
|
||||||
|
|
||||||
|
if strings.HasPrefix(str, "F") || strings.HasPrefix(str, "f") {
|
||||||
|
release = str[1:]
|
||||||
|
} else {
|
||||||
|
release = str
|
||||||
|
}
|
||||||
|
|
||||||
|
releaseN, err := strconv.Atoi(release)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
if releaseN <= 0 {
|
||||||
|
return "", errors.New("release must be a positive integer")
|
||||||
|
}
|
||||||
|
|
||||||
|
return release, nil
|
||||||
|
}
|
||||||
|
|
||||||
// PathExists wraps around os.Stat providing a nice interface for checking an existence of a path.
|
// PathExists wraps around os.Stat providing a nice interface for checking an existence of a path.
|
||||||
func PathExists(path string) bool {
|
func PathExists(path string) bool {
|
||||||
if _, err := os.Stat(path); !os.IsNotExist(err) {
|
if _, err := os.Stat(path); !os.IsNotExist(err) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue