diff --git a/config/config.go b/config/config.go index d85bd88..5608b77 100644 --- a/config/config.go +++ b/config/config.go @@ -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 { diff --git a/kode-starter b/kode-starter new file mode 100644 index 0000000..3aee170 Binary files /dev/null and b/kode-starter differ diff --git a/kode-starter.exe b/kode-starter.exe new file mode 100644 index 0000000..2643def Binary files /dev/null and b/kode-starter.exe differ diff --git a/kode-starter.go b/kode-starter.go index a813222..f2f380d 100644 --- a/kode-starter.go +++ b/kode-starter.go @@ -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() } diff --git a/makefile b/makefile new file mode 100644 index 0000000..32fb235 --- /dev/null +++ b/makefile @@ -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 \ No newline at end of file diff --git a/version/VERSION b/version/VERSION new file mode 100644 index 0000000..726017f --- /dev/null +++ b/version/VERSION @@ -0,0 +1 @@ +0.1.0.0 \ No newline at end of file diff --git a/version/version-number.go b/version/version-number.go new file mode 100644 index 0000000..95fa41d --- /dev/null +++ b/version/version-number.go @@ -0,0 +1,3 @@ +package version + +var VersionString string = "1.2.3.4.v1" diff --git a/version/version.exe b/version/version.exe new file mode 100644 index 0000000..d8bda24 Binary files /dev/null and b/version/version.exe differ diff --git a/version/version.go b/version/version.go new file mode 100644 index 0000000..a4c3cc2 --- /dev/null +++ b/version/version.go @@ -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 +} \ No newline at end of file