feat: version handling

This commit is contained in:
decentral1se 2023-12-29 15:50:26 +01:00
parent 88278955b1
commit e4ce9b6552
Signed by: decentral1se
GPG Key ID: 03789458B3D0C410
3 changed files with 50 additions and 14 deletions

View File

@ -16,10 +16,24 @@ import (
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]
A terminal client for metadata resistant messaging built on the Cwtch protocol.
_________ ________ ____ ______
/ ____/ | / _/ __ \/ __ \/ ____/
/ / / /| | / // /_/ / / / / __/
/ /___/ ___ |_/ // _, _/ /_/ / /___
\____/_/ |_/___/_/ |_/_____/_____/
Metadata resistant messaging
%s
Options:
-a turn on the Tor ACN immediately
@ -30,6 +44,14 @@ Options:
)
func main() {
if Version == "" {
Version = "pre-alpha"
}
if Commit == "" {
Commit = " "
}
cairdeVersion := fmt.Sprintf("%s commit %s", Version, Commit[:7])
var (
acnFlag bool
debugFlag bool
@ -44,39 +66,44 @@ func main() {
flag.Parse()
if helpFlag {
fmt.Print(help)
fmt.Print(fmt.Sprintf(help, cairdeVersion))
os.Exit(0)
}
if versionFlag {
fmt.Print("cairde pre-alpha v0.1.0") // TODO
fmt.Printf("%s\n", cairdeVersion)
os.Exit(0)
}
// NOTE(d1): pending https://git.coopcloud.tech/decentral1se/cairde/issues/1
_, err := exec.LookPath("tor")
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 {
log.Fatal(err)
}
defer f.Close()
filelogger, err := openPrivacyLog.NewFile(openPrivacyLog.LevelInfo, "cwtch.log")
filelogger, err := openPrivacyLog.NewFile(openPrivacyLog.LevelInfo, "cwtch.log") // TODO
if err == nil {
openPrivacyLog.SetStd(filelogger)
}
user, err := user.Current()
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(
ui.NewModel(user.Username, user.HomeDir, debugFlag),
ui.NewModel(
user.Username,
user.HomeDir,
cairdeVersion,
debugFlag,
),
tea.WithAltScreen(),
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
DEFAULT: run
@ -16,7 +20,7 @@ clean:
@find -type f -name "*.log" -exec rm '{}' \;
build: clean
@go build -ldflags="-s -w" -v ./cmd/cairde
@go build -ldflags=$(DIST_LDFLAGS) ./cmd/cairde
run: build
@./cairde

View File

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