feat: version handling

This commit is contained in:
2023-12-29 15:50:26 +01:00
parent 88278955b1
commit e4ce9b6552
3 changed files with 50 additions and 14 deletions

View File

@ -16,10 +16,24 @@ import (
tea "github.com/charmbracelet/bubbletea" tea "github.com/charmbracelet/bubbletea"
) )
const ( var (
// Version is the current version of Cairde (LDFLAGS).
Version string
// Commit is the current git commit of Cairde (LDFLAGS).
Commit string
// help is the command-line help output.
help = `cairde [options] help = `cairde [options]
A terminal client for metadata resistant messaging built on the Cwtch protocol. _________ ________ ____ ______
/ ____/ | / _/ __ \/ __ \/ ____/
/ / / /| | / // /_/ / / / / __/
/ /___/ ___ |_/ // _, _/ /_/ / /___
\____/_/ |_/___/_/ |_/_____/_____/
Metadata resistant messaging
%s
Options: Options:
-a turn on the Tor ACN immediately -a turn on the Tor ACN immediately
@ -30,6 +44,14 @@ Options:
) )
func main() { func main() {
if Version == "" {
Version = "pre-alpha"
}
if Commit == "" {
Commit = " "
}
cairdeVersion := fmt.Sprintf("%s commit %s", Version, Commit[:7])
var ( var (
acnFlag bool acnFlag bool
debugFlag bool debugFlag bool
@ -44,39 +66,44 @@ func main() {
flag.Parse() flag.Parse()
if helpFlag { if helpFlag {
fmt.Print(help) fmt.Print(fmt.Sprintf(help, cairdeVersion))
os.Exit(0) os.Exit(0)
} }
if versionFlag { if versionFlag {
fmt.Print("cairde pre-alpha v0.1.0") // TODO fmt.Printf("%s\n", cairdeVersion)
os.Exit(0) os.Exit(0)
} }
// NOTE(d1): pending https://git.coopcloud.tech/decentral1se/cairde/issues/1 // NOTE(d1): pending https://git.coopcloud.tech/decentral1se/cairde/issues/1
_, err := exec.LookPath("tor") _, err := exec.LookPath("tor")
if err != nil { if err != nil {
log.Fatal("could not find 'tor' command, is it installed?") log.Fatal("main: could not find 'tor' command, is it installed?")
} }
f, err := tea.LogToFile("cairde.log", "debug") f, err := tea.LogToFile("cairde.log", "debug") // TODO
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
defer f.Close() defer f.Close()
filelogger, err := openPrivacyLog.NewFile(openPrivacyLog.LevelInfo, "cwtch.log") filelogger, err := openPrivacyLog.NewFile(openPrivacyLog.LevelInfo, "cwtch.log") // TODO
if err == nil { if err == nil {
openPrivacyLog.SetStd(filelogger) openPrivacyLog.SetStd(filelogger)
} }
user, err := user.Current() user, err := user.Current()
if err != nil { if err != nil {
log.Fatalf("unable to determine current user: %s", err) log.Fatalf("main: unable to determine current user: %s", err)
} }
p := tea.NewProgram( p := tea.NewProgram(
ui.NewModel(user.Username, user.HomeDir, debugFlag), ui.NewModel(
user.Username,
user.HomeDir,
cairdeVersion,
debugFlag,
),
tea.WithAltScreen(), tea.WithAltScreen(),
tea.WithMouseAllMotion(), tea.WithMouseAllMotion(),
) )

View File

@ -1,3 +1,7 @@
COMMIT := $(shell git rev-list -1 HEAD)
LDFLAGS := "-X 'main.Commit=$(COMMIT)'"
DIST_LDFLAGS := $(LDFLAGS)" -s -w"
.PHONY: format check clean build run loc test .PHONY: format check clean build run loc test
DEFAULT: run DEFAULT: run
@ -16,7 +20,7 @@ clean:
@find -type f -name "*.log" -exec rm '{}' \; @find -type f -name "*.log" -exec rm '{}' \;
build: clean build: clean
@go build -ldflags="-s -w" -v ./cmd/cairde @go build -ldflags=$(DIST_LDFLAGS) ./cmd/cairde
run: build run: build
@./cairde @./cairde

View File

@ -17,7 +17,7 @@ import (
"github.com/charmbracelet/lipgloss" "github.com/charmbracelet/lipgloss"
) )
const ( var (
welcomeMessage = ` welcomeMessage = `
_________ ________ ____ ______ _________ ________ ____ ______
/ ____/ | / _/ __ \/ __ \/ ____/ / ____/ | / _/ __ \/ __ \/ ____/
@ -26,7 +26,7 @@ const (
\____/_/ |_/___/_/ |_/_____/_____/ \____/_/ |_/___/_/ |_/_____/_____/
Metadata resistant messaging Metadata resistant messaging
Pre-alpha v0.1.0 %s
Run /start for the getting started guide. Run /start for the getting started guide.
Run /help to see all available commands.` Run /help to see all available commands.`
@ -82,12 +82,14 @@ type model struct {
input textinput.Model input textinput.Model
hiddenInput string hiddenInput string
version string
statusBuffer chan string statusBuffer chan string
debug bool debug bool
} }
func NewModel(username, homeDir string, debug bool) model { // nolint:revive func NewModel(username, homeDir, version string, debug bool) model { // nolint:revive
input := textinput.New() input := textinput.New()
input.Prompt = "> " input.Prompt = "> "
input.PromptStyle = inputPromptStyle input.PromptStyle = inputPromptStyle
@ -107,6 +109,8 @@ func NewModel(username, homeDir string, debug bool) model { // nolint:revive
input: input, input: input,
version: version,
statusBuffer: make(chan string), statusBuffer: make(chan string),
showWelcomeMessage: true, showWelcomeMessage: true,
@ -195,8 +199,9 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
} }
if m.showWelcomeMessage { if m.showWelcomeMessage {
withVersion := fmt.Sprintf(welcomeMessage, m.version)
cmds = append(cmds, m.sendStatusCmd( cmds = append(cmds, m.sendStatusCmd(
strings.Split(welcomeMessage, "\n")..., strings.Split(withVersion, "\n")...,
)) ))
m.showWelcomeMessage = false m.showWelcomeMessage = false
} }