mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
update pmg banner & fix empty commit (#127)
* update pmg banner & fix empty commit * rm old banner * precompile regex for version * fix: Color in github URL (#128) --------- Co-authored-by: Abhisek Datta <abhisek.datta@gmail.com>
This commit is contained in:
co-authored by
Abhisek Datta
parent
edfdd543e0
commit
ff4a4a4734
+31
-4
@@ -2,6 +2,8 @@ package ui
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
)
|
)
|
||||||
@@ -9,19 +11,44 @@ import (
|
|||||||
var (
|
var (
|
||||||
brandPinkRed = color.RGB(219, 39, 119).Add(color.Bold).SprintFunc() // #DB2777 Brand Pink
|
brandPinkRed = color.RGB(219, 39, 119).Add(color.Bold).SprintFunc() // #DB2777 Brand Pink
|
||||||
whiteDim = color.New(color.Faint).SprintFunc()
|
whiteDim = color.New(color.Faint).SprintFunc()
|
||||||
|
pseudoPattern = regexp.MustCompile(`^(v?\d+\.\d+\.\d+)-0\.\d{14}-[a-f0-9]{12}$`)
|
||||||
)
|
)
|
||||||
|
|
||||||
func GeneratePMGBanner(version, commit string) string {
|
func GeneratePMGBanner(version, commit string) string {
|
||||||
var pmgASCIIText = `
|
// Build the first line with a differently colored URL segment
|
||||||
█▀█ █▀▄▀█ █▀▀ From SafeDep
|
line1 := fmt.Sprintf("%s\tFrom SafeDep %s", brandPinkRed("█▀█ █▀▄▀█ █▀▀"), whiteDim("(github.com/safedep/pmg)"))
|
||||||
█▀▀ █░▀░█ █▄█` // It should end here no \n
|
line2 := brandPinkRed("█▀▀ █░▀░█ █▄█")
|
||||||
|
|
||||||
|
pmgASCIIText := "\n" + line1 + "\n" + line2 // It should end here no \n
|
||||||
|
|
||||||
if len(commit) >= 6 {
|
if len(commit) >= 6 {
|
||||||
commit = commit[:6]
|
commit = commit[:6]
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("%s %s: %s %s: %s\n\n", brandPinkRed(pmgASCIIText),
|
// Clean version to remove pseudo-version complexity
|
||||||
|
version = cleanVersion(version)
|
||||||
|
|
||||||
|
return fmt.Sprintf("%s %s: %s %s: %s\n\n", pmgASCIIText,
|
||||||
whiteDim("version"), Colors.Bold(version),
|
whiteDim("version"), Colors.Bold(version),
|
||||||
whiteDim("commit"), Colors.Bold(commit),
|
whiteDim("commit"), Colors.Bold(commit),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cleanVersion removes ugly pseudo-version timestamps and dirty flags
|
||||||
|
// Keeps clean versions like v1.2.3-alpha.1 and v0.3.5-edfdd54 as-is
|
||||||
|
func cleanVersion(version string) string {
|
||||||
|
if version == "" {
|
||||||
|
return version
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove build metadata (+dirty, +build.1, etc.)
|
||||||
|
version = strings.Split(version, "+")[0]
|
||||||
|
|
||||||
|
// Only clean pseudo-versions with timestamps
|
||||||
|
// Pattern: v1.2.3-0.20220101123456-abcdef123456
|
||||||
|
if matches := pseudoPattern.FindStringSubmatch(version); len(matches) > 1 {
|
||||||
|
return matches[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
return version
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,8 +8,21 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
buildInfo, ok := runtimeDebug.ReadBuildInfo()
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if Version == "" {
|
if Version == "" {
|
||||||
buildInfo, _ := runtimeDebug.ReadBuildInfo()
|
|
||||||
Version = buildInfo.Main.Version
|
Version = buildInfo.Main.Version
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if Commit == "" {
|
||||||
|
for _, setting := range buildInfo.Settings {
|
||||||
|
if setting.Key == "vcs.revision" {
|
||||||
|
Commit = setting.Value
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user