go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/cnquery.go (about) 1 // Copyright (c) Mondoo, Inc. 2 // SPDX-License-Identifier: BUSL-1.1 3 4 package cnquery 5 6 import ( 7 "regexp" 8 ) 9 10 // Version is set via ldflags 11 var Version string 12 13 // Build version is set via ldflags 14 var Build string 15 16 // Date is set via ldflags 17 var Date string 18 19 /* 20 versioning follows semver guidelines: https://semver.org/ 21 22 <valid semver> ::= <version core> 23 | <version core> "-" <pre-release> 24 | <version core> "+" <build> 25 | <version core> "-" <pre-release> "+" <build> 26 27 <version core> ::= <major> "." <minor> "." <patch> 28 29 <major> ::= <numeric identifier> 30 31 <minor> ::= <numeric identifier> 32 33 <patch> ::= <numeric identifier> 34 */ 35 36 // GetVersion returns the version of the build 37 // valid semver version including build version (e.g. 4.10.0+4900), where 4900 is a forward rolling int 38 func GetVersion() string { 39 if Version == "" { 40 return "unstable" 41 } 42 return Version 43 } 44 45 var coreSemverRegex = regexp.MustCompile(`^(\d+.\d+.\d+)`) 46 47 // GetCoreVersion returns the semver core (i.e. major.minor.patch) 48 func GetCoreVersion() string { 49 v := Version 50 51 if v != "" { 52 v = coreSemverRegex.FindString(v) 53 } 54 55 if v == "" { 56 return "unstable" 57 } 58 return v 59 } 60 61 // GetBuild returns the git sha of the build 62 func GetBuild() string { 63 b := Build 64 if len(b) == 0 { 65 b = "development" 66 } 67 return b 68 } 69 70 // GetDate returns the date of this build 71 func GetDate() string { 72 d := Date 73 if len(d) == 0 { 74 d = "unknown" 75 } 76 return d 77 } 78 79 var majorVersionRegex = regexp.MustCompile(`^(\d+)`) 80 81 // APIVersion is the major version of the version string (e.g. 4) 82 func APIVersion() string { 83 v := Version 84 85 if v != "" { 86 v = majorVersionRegex.FindString(v) 87 } 88 89 if v == "" { 90 return "unstable" 91 } 92 return v 93 } 94 95 // Info on this application with version and build 96 func Info() string { 97 return "cnquery " + GetVersion() + " (" + GetBuild() + ", " + GetDate() + ")" 98 } 99 100 // LatestMQLVersion returns the current version of MQL 101 func LatestMQLVersion() string { 102 return "v2" 103 }