mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-19 16:47:28 +01:00
Add a "wuffs genrelease" command
This commit is contained in:
1 parent
beed8a1c52
commit
dccf0c60d7
9 files changed
+479
-38
No files matched your search
@@ -19,7 +19,9 @@
|
||||
package commonflags
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -44,13 +46,16 @@ const (
|
||||
RepsMin = 0
|
||||
RepsMax = 1000000
|
||||
RepsUsage = `the number of repetitions per benchmark`
|
||||
|
||||
VersionDefault = "0.0.0"
|
||||
VersionUsage = `version string, e.g. "1.2.3-beta.4"`
|
||||
)
|
||||
|
||||
// TODO: do IsAlphaNumericIsh and IsValidUsePath belong in a separate package,
|
||||
// such as lang/validate? Perhaps together with token.Unescape?
|
||||
|
||||
// IsAlphaNumericIsh returns whether s contains only ASCII alpha-numerics and a
|
||||
// limited set of punctuation such as commas and slahes, but not containing
|
||||
// limited set of punctuation such as commas and slashes, but not containing
|
||||
// e.g. spaces, semi-colons, colons or backslashes.
|
||||
//
|
||||
// The intent is that if s is alpha-numeric-ish, then it should not need
|
||||
@@ -70,3 +75,35 @@ func IsAlphaNumericIsh(s string) bool {
|
||||
func IsValidUsePath(s string) bool {
|
||||
return s == path.Clean(s) && s != "" && s[0] != '.' && s[0] != '/'
|
||||
}
|
||||
|
||||
type Version struct {
|
||||
Major uint32
|
||||
Minor uint16
|
||||
Patch uint16
|
||||
Extension string
|
||||
}
|
||||
|
||||
func ParseVersion(s string) (v Version, ok bool) {
|
||||
if !IsAlphaNumericIsh(s) {
|
||||
return Version{}, false
|
||||
}
|
||||
if i := strings.IndexByte(s, '-'); i >= 0 {
|
||||
s, v.Extension = s[:i], s[i+1:]
|
||||
}
|
||||
if _, err := fmt.Sscanf(s, "%d.%d.%d", &v.Major, &v.Minor, &v.Patch); err != nil {
|
||||
return Version{}, false
|
||||
}
|
||||
return v, true
|
||||
}
|
||||
|
||||
func (v Version) String() string {
|
||||
s := fmt.Sprintf("%d.%d.%d", v.Major, v.Minor, v.Patch)
|
||||
if v.Extension != "" {
|
||||
s += "-" + v.Extension
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func (v Version) Uint64() uint64 {
|
||||
return (uint64(v.Major) << 32) | (uint64(v.Minor) << 16) | (uint64(v.Patch) << 0)
|
||||
}
|
||||
Reference in new issue
Block a user