fix: change how version is retrieved

fg-job
TorchedSammy 2022-05-16 19:36:34 -04:00
parent cb88db8cfc
commit ac21109307
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
4 changed files with 26 additions and 4 deletions

View File

@ -6,7 +6,7 @@ MY_GOFLAGS = -ldflags "-s -w"
all: dev all: dev
dev: MY_GOFLAGS = -ldflags "-s -w -X main.version=$(shell git describe --tags)" dev: MY_GOFLAGS = -ldflags "-s -w -X main.gitCommit=$(shell git rev-parse --short HEAD) -X main.gitBranch=$(shell git rev-parse --abbrev-ref HEAD)"
dev: build dev: build
build: build:

2
api.go
View File

@ -107,7 +107,7 @@ func hilbishLoad(rtm *rt.Runtime) (rt.Value, func()) {
The nice lil shell for {blue}Lua{reset} fanatics! The nice lil shell for {blue}Lua{reset} fanatics!
Check out the {blue}{bold}guide{reset} command to get started. Check out the {blue}{bold}guide{reset} command to get started.
` `
util.SetFieldProtected(fakeMod, mod, "ver", rt.StringValue(version), "Hilbish version") util.SetFieldProtected(fakeMod, mod, "ver", rt.StringValue(getVersion()), "Hilbish version")
util.SetFieldProtected(fakeMod, mod, "user", rt.StringValue(username), "Username of user") util.SetFieldProtected(fakeMod, mod, "user", rt.StringValue(username), "Username of user")
util.SetFieldProtected(fakeMod, mod, "host", rt.StringValue(host), "Host name of the machine") util.SetFieldProtected(fakeMod, mod, "host", rt.StringValue(host), "Host name of the machine")
util.SetFieldProtected(fakeMod, mod, "home", rt.StringValue(curuser.HomeDir), "Home directory of the user") util.SetFieldProtected(fakeMod, mod, "home", rt.StringValue(curuser.HomeDir), "Home directory of the user")

17
main.go
View File

@ -106,7 +106,7 @@ func main() {
} }
if *verflag { if *verflag {
fmt.Printf("Hilbish %s\n", version) fmt.Printf("Hilbish %s\n", getVersion())
os.Exit(0) os.Exit(0)
} }
@ -303,3 +303,18 @@ func exit(code int) {
} }
} }
} }
func getVersion() string {
v := strings.Builder{}
v.WriteString(ver)
if gitBranch != "" && gitBranch != "HEAD" {
v.WriteString("-" + gitBranch)
}
if gitCommit != "" {
v.WriteString("." + gitCommit)
}
return v.String()
}

View File

@ -2,7 +2,6 @@ package main
// String vars that are free to be changed at compile time // String vars that are free to be changed at compile time
var ( var (
version = "v2.0.0"
defaultHistDir = "" defaultHistDir = ""
commonRequirePaths = "';./libs/?/init.lua;./?/init.lua;./?/?.lua'" commonRequirePaths = "';./libs/?/init.lua;./?/init.lua;./?/?.lua'"
@ -10,6 +9,14 @@ var (
multilinePrompt = "> " multilinePrompt = "> "
) )
// Version info
var (
ver = "v2.0.0"
releaseName = "Hibiscus"
gitCommit string
gitBranch string
)
// Flags // Flags
var ( var (
running bool // Is a command currently running running bool // Is a command currently running