add version

This commit is contained in:
bcharest 2023-06-14 23:33:24 -04:00
parent 9547004867
commit 06f1fb2924
9 changed files with 101 additions and 4 deletions

View File

@ -1,12 +1,20 @@
package config
import (
"fmt"
"kode-starter/utils"
"kode-starter/version"
"os"
"github.com/spf13/cobra"
)
var version string = "0.0.1"
// var version string = "0.0.1"
// var fullVersion string = version.FullVersion()
// var fullVersion, err = version.ReadVersionFile()
// var fullVersion string
var author string = "Bruno Charest"
@ -24,8 +32,15 @@ var urlApiBase string = urlBase + "/api/v1"
var urlApiOrgs string = urlApiBase + "/orgs"
func GetVersion() string {
return version
func GetVersion() *version.Version {
fullVersion, err := version.NewVersionFromString(version.VersionString)
if err != nil {
fmt.Println("Error:", err)
os.Exit(1)
}
return fullVersion
}
func GetAuthor() string {

BIN
kode-starter Normal file

Binary file not shown.

BIN
kode-starter.exe Normal file

Binary file not shown.

View File

@ -207,13 +207,17 @@ func printHelpFormated(cmd *cobra.Command) {
cmd.Help()
fmt.Println("")
fmt.Println(line)
fmt.Println("| Version: " + config.GetVersion() + " || Author: " + config.GetAuthor() + " || Build date: " + config.GetBuildDate() + " |")
fmt.Println("| Version: " + config.GetVersion().String() + " || Author: " + config.GetAuthor() + " || Build date: " + config.GetBuildDate() + " |")
fmt.Println(line)
fmt.Println("")
}
func main() {
fmt.Println("==> Project Creator CLI")
versionString := config.GetVersion()
fmt.Println(versionString)
rootCmd.Execute()
}

26
makefile Normal file
View File

@ -0,0 +1,26 @@
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
# Binary name
BINARY_NAME=kode-starter
all: test build
build:
$(GOBUILD) -o $(BINARY_NAME) -v
test:
$(GOTEST) -v ./...
clean:
$(GOCLEAN)
rm -f $(BINARY_NAME)
release: clean
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -o $(BINARY_NAME) -v
.PHONY: all build test clean release

1
version/VERSION Normal file
View File

@ -0,0 +1 @@
0.1.0.0

View File

@ -0,0 +1,3 @@
package version
var VersionString string = "1.2.3.4.v1"

BIN
version/version.exe Normal file

Binary file not shown.

48
version/version.go Normal file
View File

@ -0,0 +1,48 @@
package version
import (
"fmt"
"strconv"
"strings"
)
type Version struct {
Major int
Minor int
Patch int
Build int
VersionNumberToIncrement string // New field
}
func (v Version) String() string {
return fmt.Sprintf("%d.%d.%d.%d", v.Major, v.Minor, v.Patch, v.Build)
}
func NewVersionFromString(versionString string) (*Version, error) {
parts := strings.Split(versionString, ".")
if len(parts) != 5 { // Update length check for new field
return nil, fmt.Errorf("invalid version string: %s", versionString)
}
major, err := strconv.Atoi(parts[0])
if err != nil {
return nil, fmt.Errorf("invalid major version: %s", parts[0])
}
minor, err := strconv.Atoi(parts[1])
if err != nil {
return nil, fmt.Errorf("invalid minor version: %s", parts[1])
}
patch, err := strconv.Atoi(parts[2])
if err != nil {
return nil, fmt.Errorf("invalid patch version: %s", parts[2])
}
build, err := strconv.Atoi(parts[3])
if err != nil {
return nil, fmt.Errorf("invalid build version: %s", parts[3])
}
return &Version{major, minor, patch, build, parts[4]}, nil // Initialize new field
}