-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change version via Makefile(incomplete)
- Loading branch information
1 parent
270358f
commit 826b8f7
Showing
5 changed files
with
135 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
setup: | ||
GO_FLAGS ?= | ||
NAME := cloudlens | ||
OUTPUT_BIN ?= execs/${NAME} | ||
PACKAGE := github.com/one2nc/$(NAME) | ||
VERSION ?= v0.26.10 | ||
|
||
ßsetup: | ||
docker-compose up -d | ||
|
||
setup-down: | ||
docker ps -a --format "{{.ID}} {{.Names}}" | grep cloudlens| awk '{print $$1}'| xargs docker stop | xargs docker rm -v | ||
|
||
build: | ||
go build -o cloudlens main.go | ||
|
||
go build \ | ||
-ldflags "-w -s -X ${PACKAGE}/cmd.version=${VERSION}" \ | ||
-a -tags netgo -o ${OUTPUT_BIN} main.go | ||
|
||
run: build | ||
./cloudlens | ||
./execs/cloudlens | ||
|
||
populate: build | ||
./cloudlens lspop | ||
./execs/cloudlens lspop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,67 @@ | ||
package cmd | ||
|
||
// import ( | ||
// "fmt" | ||
|
||
// "github.com/spf13/cobra" | ||
// ) | ||
|
||
// func versionCmd() *cobra.Command { | ||
// var command = &cobra.Command{ | ||
// Use: "version", | ||
// Short: "Print version/build info", | ||
// Long: "Print version/build information", | ||
// Run: func(cmd *cobra.Command, args []string) { | ||
// printVersion() | ||
// }, | ||
// } | ||
// return command | ||
// } | ||
|
||
// func printVersion() { | ||
// fmt.Println(version) | ||
// } | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/one2nc/cloud-lens/internal/color" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var command = &cobra.Command{ | ||
Use: "version", | ||
Short: "Print version/build info", | ||
Long: "Print version/build information", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
printVersion("version") | ||
}, | ||
func versionCmd() *cobra.Command { | ||
var short bool | ||
|
||
command := cobra.Command{ | ||
Use: "version", | ||
Short: "Print version/build info", | ||
Long: "Print version/build information", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
printVersion(short) | ||
}, | ||
} | ||
|
||
command.PersistentFlags().BoolVarP(&short, "short", "s", false, "Prints cloudlens version info in short format") | ||
|
||
return &command | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(command) | ||
func printVersion(short bool) { | ||
const fmat = "%-20s %s\n" | ||
var outputColor color.Paint | ||
|
||
if short { | ||
outputColor = -1 | ||
} | ||
printTuple(fmat, "Version", version, outputColor) | ||
// printTuple(fmat, "Commit", commit, outputColor) | ||
// printTuple(fmat, "Date", date, outputColor) | ||
} | ||
|
||
func printVersion(fmat string) { | ||
fmt.Println(version) | ||
func printTuple(fmat, section, value string, outputColor color.Paint) { | ||
if outputColor != -1 { | ||
fmt.Fprintf(out, fmat, color.Colorize(section+":", outputColor), value) | ||
return | ||
} | ||
fmt.Fprintf(out, fmat, section, value) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package model | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"strconv" | ||
) | ||
|
||
var versionRX = regexp.MustCompile(`\Av(\d+)\.(\d+)\.(\d+)\z`) | ||
|
||
// SemVer represents a semantic version. | ||
type SemVer struct { | ||
Major, Minor, Patch int | ||
} | ||
|
||
// NewSemVer returns a new semantic version. | ||
func NewSemVer(version string) *SemVer { | ||
var v SemVer | ||
v.Major, v.Minor, v.Patch = v.parse(NormalizeVersion(version)) | ||
|
||
return &v | ||
} | ||
|
||
// String returns version as a string. | ||
func (v *SemVer) String() string { | ||
return fmt.Sprintf("v%d.%d.%d", v.Major, v.Minor, v.Patch) | ||
} | ||
|
||
func (*SemVer) parse(version string) (major, minor, patch int) { | ||
mm := versionRX.FindStringSubmatch(version) | ||
if len(mm) < 4 { | ||
return | ||
} | ||
major, _ = strconv.Atoi(mm[1]) | ||
minor, _ = strconv.Atoi(mm[2]) | ||
patch, _ = strconv.Atoi(mm[3]) | ||
|
||
return | ||
} | ||
|
||
// NormalizeVersion ensures the version starts with a v. | ||
func NormalizeVersion(version string) string { | ||
fmt.Println("inside normalise") | ||
if version == "" { | ||
return version | ||
} | ||
if version[0] == 'v' { | ||
return version | ||
} | ||
return "v" + version | ||
} | ||
|
||
// IsCurrent asserts if at latest release. | ||
func (v *SemVer) IsCurrent(latest *SemVer) bool { | ||
return v.Major >= latest.Major && v.Minor >= latest.Minor && v.Patch >= latest.Patch | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters