Skip to content

Commit

Permalink
(build): update version command to return build info instead of a sta…
Browse files Browse the repository at this point in the history
…tic version (#42)

Signed-off-by: everettraven <[email protected]>
  • Loading branch information
everettraven authored Dec 6, 2023
1 parent 0269b93 commit 594dac8
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
26 changes: 23 additions & 3 deletions internal/cli/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
},
}
12 changes: 6 additions & 6 deletions pkg/charm/styles/styles.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,38 @@ 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 {
return lipgloss.NewStyle().Align(lipgloss.Center, lipgloss.Center)
}

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 {
Expand Down

0 comments on commit 594dac8

Please sign in to comment.