From 594dac8eeb73a779ce057342479a1b99ccde17d2 Mon Sep 17 00:00:00 2001 From: Bryce Palmer Date: Wed, 6 Dec 2023 11:01:31 -0500 Subject: [PATCH] (build): update version command to return build info instead of a static version (#42) Signed-off-by: everettraven --- Makefile | 4 +--- go.mod | 1 + go.sum | 2 ++ internal/cli/version.go | 26 +++++++++++++++++++++++--- pkg/charm/styles/styles.go | 12 ++++++------ 5 files changed, 33 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 41f07c5..afab973 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,6 @@ include .bingo/Variables.mk export GIT_VERSION ?= $(shell git describe --tags --always --dirty) export VERSION_PKG ?= $(shell go list -m)/internal/cli export GO_BUILD_ASMFLAGS ?= all=-trimpath=${PWD} -export GO_BUILD_LDFLAGS ?= -s -w -X "$(VERSION_PKG).version=$(GIT_VERSION)" export GO_BUILD_GCFLAGS ?= all=-trimpath=${PWD} export IMAGE_REPO ?= docker.io/bpalmer/buoy @@ -12,9 +11,8 @@ export IMAGE_TAG ?= devel build: go build \ -asmflags '$(GO_BUILD_ASMFLAGS)' \ - -ldflags '$(GO_BUILD_LDFLAGS)' \ -gcflags '$(GO_BUILD_GCFLAGS)' \ - -o buoy main.go + -o buoy . export ENABLE_RELEASE_PIPELINE ?= false export GORELEASER_ARGS ?= --snapshot --clean diff --git a/go.mod b/go.mod index a5a6760..c38d856 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/charmbracelet/bubbles v0.16.1 github.com/charmbracelet/bubbletea v0.24.2 github.com/charmbracelet/lipgloss v0.7.1 + github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be github.com/sahilm/fuzzy v0.1.0 github.com/spf13/cobra v1.7.0 github.com/tidwall/gjson v1.17.0 diff --git a/go.sum b/go.sum index 74ef5fd..aaffdad 100644 --- a/go.sum +++ b/go.sum @@ -12,6 +12,8 @@ github.com/charmbracelet/bubbletea v0.24.2 h1:uaQIKx9Ai6Gdh5zpTbGiWpytMU+CfsPp06 github.com/charmbracelet/bubbletea v0.24.2/go.mod h1:XdrNrV4J8GiyshTtx3DNuYkR1FDaJmO3l2nejekbsgg= github.com/charmbracelet/lipgloss v0.7.1 h1:17WMwi7N1b1rVWOjMT+rCh7sQkvDU75B2hbZpc5Kc1E= github.com/charmbracelet/lipgloss v0.7.1/go.mod h1:yG0k3giv8Qj8edTCbbg6AlQ5e8KNWpFujkNawKNhE2c= +github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be h1:J5BL2kskAlV9ckgEsNQXscjIaLiOYiZ75d4e94E6dcQ= +github.com/common-nighthawk/go-figure v0.0.0-20210622060536-734e95fb86be/go.mod h1:mk5IQ+Y0ZeO87b858TlA645sVcEcbiX6YqP98kt+7+w= github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 h1:q2hJAaP1k2wIvVRd/hEHD7lacgqrCPS+k8g1MndzfWY= github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= diff --git a/internal/cli/version.go b/internal/cli/version.go index bfbc8b7..f7cd015 100644 --- a/internal/cli/version.go +++ b/internal/cli/version.go @@ -2,16 +2,36 @@ package cli import ( "fmt" + "runtime/debug" + "strings" + "github.com/charmbracelet/lipgloss" + figure "github.com/common-nighthawk/go-figure" + "github.com/everettraven/buoy/pkg/charm/styles" "github.com/spf13/cobra" ) -var version = "unknown" - var versionCommand = &cobra.Command{ Use: "version", Short: "installed version of buoy", Run: func(cmd *cobra.Command, args []string) { - fmt.Println("buoy", version) + var out strings.Builder + fig := figure.NewFigure("buoy", "rounded", true) + header := lipgloss.NewStyle(). + Border(lipgloss.NormalBorder(), false, false, true). + BorderForeground(styles.DefaultColor). + Render(fig.String()) + + out.WriteString(header + "\n\n") + settingNameStyle := lipgloss.NewStyle().Bold(true) + if bi, ok := debug.ReadBuildInfo(); ok { + for _, setting := range bi.Settings { + name := settingNameStyle.Render(setting.Key) + out.WriteString(fmt.Sprintf("%s: %s\n", name, setting.Value)) + } + } else { + out.WriteString("unable to read build info") + } + fmt.Print(out.String()) }, } diff --git a/pkg/charm/styles/styles.go b/pkg/charm/styles/styles.go index 50acd95..0ec5bed 100644 --- a/pkg/charm/styles/styles.go +++ b/pkg/charm/styles/styles.go @@ -2,26 +2,26 @@ package styles import "github.com/charmbracelet/lipgloss" -var adaptColor = lipgloss.AdaptiveColor{Light: "63", Dark: "117"} +var DefaultColor = lipgloss.AdaptiveColor{Light: "63", Dark: "117"} func SelectedTabStyle() lipgloss.Style { border := lipgloss.RoundedBorder() border.BottomLeft = "┘" border.Bottom = " " border.BottomRight = "└" - return lipgloss.NewStyle().Bold(true).Align(lipgloss.Center).Border(border).BorderForeground(adaptColor).Padding(0, 1) + return lipgloss.NewStyle().Bold(true).Align(lipgloss.Center).Border(border).BorderForeground(DefaultColor).Padding(0, 1) } func TabStyle() lipgloss.Style { border := lipgloss.RoundedBorder() border.BottomLeft = "┴" border.BottomRight = "┴" - return lipgloss.NewStyle().Bold(true).Align(lipgloss.Center).Border(border).BorderForeground(adaptColor).Padding(0, 1) + return lipgloss.NewStyle().Bold(true).Align(lipgloss.Center).Border(border).BorderForeground(DefaultColor).Padding(0, 1) } func TabGap() lipgloss.Style { border := lipgloss.RoundedBorder() - return lipgloss.NewStyle().Bold(true).Align(lipgloss.Center).Border(border, false, false, true, false).BorderForeground(adaptColor).Padding(0, 1) + return lipgloss.NewStyle().Bold(true).Align(lipgloss.Center).Border(border, false, false, true, false).BorderForeground(DefaultColor).Padding(0, 1) } func ContentStyle() lipgloss.Style { @@ -29,11 +29,11 @@ func ContentStyle() lipgloss.Style { } func TableSelectedRowStyle() lipgloss.Style { - return lipgloss.NewStyle().Foreground(adaptColor) + return lipgloss.NewStyle().Foreground(DefaultColor) } func LogSearchHighlightStyle() lipgloss.Style { - return lipgloss.NewStyle().Foreground(adaptColor) + return lipgloss.NewStyle().Foreground(DefaultColor) } func LogSearchModeStyle() lipgloss.Style {